kotak berputar

Rabu, 21 Desember 2011


KOTAK PUTAR:
package soal1;
import java.awt.Color;
import javax.swing.JFrame;
public class kotakPutar extends Thread{
   private static kotak shapes2JPanel;
   public static void main( String args[] ){
      JFrame frame = new JFrame( "Drawing 2D Shapes" );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      shapes2JPanel = new kotak();
      frame.add( shapes2JPanel ); 
      frame.setBackground( Color.WHITE ); 
      frame.setSize( 400, 400 ); 
      frame.setVisible( true ); 
      kotakPutar sh=new kotakPutar();
      sh.start();
   }
   @Override
    public void run(){
        while (true){
            try{this.sleep(500);}
            catch(InterruptedException ie){break;}
            shapes2JPanel.repaint();
        }
    }





KOTAK:

package soal1;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.util.Random;
import javax.swing.*;
public class kotak extends JPanel{
    private static GeneralPath gp;
    int jum=1;
    @Override
   public void paintComponent( Graphics g ){
      super.paintComponent( g ); 
      Random random = new Random(); 
      Graphics2D g2d = ( Graphics2D ) g;
      g2d.translate( 200, 200 ); 
      if (jum==18)
          jum=0;
      for ( int count = 1; count <= jum; count++ ){
         g2d.rotate( Math.PI / 4.0 ); // rotate coordinate system
         g2d.setColor( new Color( random.nextInt( 256 ),
            random.nextInt( 256 ), random.nextInt( 256 ) ) );
         g2d.fillRect(0, 0, 80, 80);
      } 
      jum++;
   } 
   public GeneralPath starImage(){
      int xPoints[] = { 60, 10, 120 };
      int yPoints[] = { 10, 60, 60 };
      GeneralPath star = new GeneralPath(); // create GeneralPath object
      star.moveTo( xPoints[ 45 ], yPoints[ 45 ] );
      for ( int count = 1; count < xPoints.length; count++ )
         star.lineTo( xPoints[ count ], yPoints[ count ] );
      star.closePath(); 
      return star;
    }


Get This Comment Form

0 comment(s):

 
Copyright© 2010 Felisitas Brillianti | Semelekete Weleh Weleh | http://dr214ac.blogspot.com