All pastes #8891 Raw Edit

Untitled

public java v1 · immutable
#8891 ·published 2005-04-06 01:33 UTC
rendered paste body
/** GOAL:   Print the TEXT over the other graphics stuff      PROBLEM:     The screen flickers when the method is enabled, do not understand why.*/import java.awt.*;import java.awt.event.*;import java.awt.geom.*;import javax.swing.*;public class GenPath  extends JFrame {float dashes[] = { 10, 2 }; //for the yellow line   // set window's title bar String and background color   public GenPath ()   {      super( "Drawing a GeneralPath over other stuff." );      getContentPane().setBackground( Color.gray );   }    // draw general paths   public void paint( Graphics g )   {      // call superclass' paint method      super.paint( g );      Graphics2D graphics2D = ( Graphics2D ) g;            //these are the x/y variables for the points on the "angleLine"      int xPoints[] =          { 350,220,180,200,250 };      int yPoints[] =          { 60,100,90,80,85};                     //graphics2D.translate( 400, 400 );                  // draw 2D lines in green and yellow      graphics2D.setPaint( Color.green );      graphics2D.draw( new Line2D.Double( 295, 30, 220, 150 ) );            //the yellow line      graphics2D.setPaint( Color.yellow );          graphics2D.setStroke( new BasicStroke(          8, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND,          10, dashes, 0 ) );       graphics2D.draw( new Line2D.Double( 220, 30, 295, 150 ) );                  //set color for the changing line       graphics2D.setPaint( Color.black );      // create a star from a series of points      GeneralPath angleLine = new GeneralPath();                  // set the initial coordinate of the General Path      angleLine.moveTo( xPoints[ 0 ], yPoints[ 0 ] );       //!?!?! the 0 is not COORDS idiot!!! it's the ARRAY value 0!!!!! ?!?!? dammit lol     // create the star--this does not draw the star      for ( int count = 1; count < xPoints.length; count++ )         angleLine.lineTo( xPoints[ count ], yPoints[ count ] );	// close the shape      angleLine.closePath();            // translate the origin to (200, 200)      //graphics2D.translate( 400, 400 );	      graphics2D.fill( angleLine );                         /**   Trying for TEXT */   /***************************************this is the problem area, and/or METHOD */      //** the APP flickers constantly, when this is enabled */      //Graphics2D g2d = ( Graphics2D ) g;    /////////////////////////////////////////////COMMENT the below line ?!?! and you will see that the APP functions (without TXT)      drawTheText(graphics2D);     /**   Trying for TEXT */          }  // end method paint       protected void drawTheText(Graphics2D graphics2D) {        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();    env.getAvailableFontFamilyNames();    setFont(new Font("Goudy Handtooled BT", Font.PLAIN, 100));        graphics2D.setPaint(Color.orange);    graphics2D.drawString("Java 2D", 25, 215);     }                // execute application   public static void main( String args[] )   {      GenPath  application = new GenPath ();      application.setDefaultCloseOperation(         JFrame.EXIT_ON_CLOSE );      application.setSize( 425, 160 );      application.setVisible( true );      }}