Postingan

Menampilkan postingan dari Desember 22, 2011

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 ),         

shape latihan

panel shape:| import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.RoundRectangle2D; import javax.swing.JPanel; /**  *  * @author admin  */ public class ShapePanel extends JPanel {     public ShapePanel() {         setBackground(Color.white);     }     @Override     public void paintComponent(Graphics g) {         super.paintComponent(g);         g.setColor(Color.BLUE);         g.drawLine(0, 10, 50, 60);         g.setColor(Color.red);         g.drawRect(50, 10, 50, 50);         g.setColor(new Color(255, 0, 0));         g.fillOval(100, 10, 50, 50);         g.setColor(new Color(0, 255, 0));         g.fillArc(150, 10, 50, 50, 0, 180);         Graphics2D g2 = (Graphics2D) g; // fill RoundRectangle2D.Double         GradientPaint redtowhite = new GradientPaint(200, 10, Color.red, 250, 10, Color.black);         g2.setPaint(redtowhite);         g2.fill(new RoundRectangle2D.Double(200,

shape...

import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.GeneralPath; import java.util.Random; import javax.swing.JPanel; public class Shapes2JPanel extends JPanel {    // draw general paths     @Override    public void paintComponent( Graphics g )    {       super.paintComponent( g ); // call superclass's paintComponent       Random random = new Random(); // get random number generator //      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 };       Graphics2D g2d = ( Graphics2D ) g;       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++