tread bintang UTS

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import java.util.Random;
import javax.swing.JPanel;

public class Bintang extends JPanel
{
    private static GeneralPath gp;
    int jum=1;
       
   // draw general paths
    @Override
   public void paintComponent( Graphics g )
   {
      super.paintComponent( g ); // call superclass's paintComponent
      Random random = new Random(); // get random number generator
      Graphics2D g2d = ( Graphics2D ) g;
     

      g2d.translate( 200, 200 ); // translate the origin to (200, 200)

      if (jum==18)
          jum=0;
      // rotate around origin and draw stars in random colors
      for ( int count = 1; count <= jum; count++ )
      {
         g2d.rotate( Math.PI / 9.0 ); // rotate coordinate system

         // set random drawing color
         g2d.setColor( new Color( random.nextInt( 256 ),
            random.nextInt( 256 ), random.nextInt( 256 ) ) );

         g2d.fill( new Rectangle2D.Double(0, 0, 70, 70) ); // draw filled star
      } // end for
      jum++;
   } // end method paintComponent

   public GeneralPath starImage()
    {
//        int xPoints[] = { 55, 67, 109, 73, 83, 55, 27, 37, 1, 43 };
//      int yPoints[] = { 0, 36, 36, 54, 96, 72, 96, 54, 36, 36 };
      int xPoints[] = { 60, 0, 120 };
      int yPoints[] = { 0, 60, 60 };

      GeneralPath star = new GeneralPath(); // create GeneralPath object

      // set the initial coordinate of the General Path
      star.moveTo( xPoints[ 0 ], yPoints[ 0 ] );

      // create the star--this does not draw the star
      for ( int count = 1; count < xPoints.length; count++ )
         star.lineTo( xPoints[ count ], yPoints[ count ] );

      star.closePath(); // close the shape
      return star;
    }
} // end class Bintang


main :



import java.awt.Color;
import javax.swing.JFrame;

public class ThreadBintang extends Thread
{
   // execute application
   private static Bintang shapes2JPanel;
   public static void main( String args[] )
   {
      // create frame for Shapes2JPanel
      JFrame frame = new JFrame( "Drawing 2D Shapes" );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

      shapes2JPanel = new Bintang();
      frame.add( shapes2JPanel ); // add shapes2JPanel to frame
      frame.setBackground( Color.WHITE ); // set frame background color
      frame.setSize( 400, 400 ); // set frame size
      frame.setVisible( true ); // display frame
      ThreadBintang sh=new ThreadBintang();
      sh.start();
   } // end main


    @Override
    public void run(){
        while (true){
            try{
                this.sleep(200);
            }
            catch(InterruptedException ie){break;}
            shapes2JPanel.repaint();
        }
    }

} // end class Shapes2

Komentar

Postingan populer dari blog ini

Bikin Amplop Cantik

Menyesap Rindu Dalam Coding (Sastra Edan #7)

Kost Anyar Nyah...