Advertisement
lilflamekid91

Lab 2 - Draw Class

May 23rd, 2013
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class Draw extends JPanel{
  5.  
  6.        
  7.         public void drawing(){
  8.             repaint();
  9.         }
  10.        
  11.         public void paintComponent(Graphics g){
  12.             super.paintComponents(g);
  13.             g.setColor(Color.RED);
  14.            
  15.             g.fillRect(200,0,600,40);
  16.             g.fillRect(200,80,600,40);
  17.             g.fillRect(200,160,600,40);
  18.             g.fillRect(0,240,800,40);
  19.             g.fillRect(0,320,800,40);
  20.             g.fillRect(0,400,800,40);
  21.        
  22.            
  23.             g.setColor(Color.BLUE);
  24.             g.fillRect(0,0,200,200);
  25.            
  26.    
  27.             int w = 170;
  28.             int h = 170;
  29.             int x = 15;
  30.             int y = 15;
  31.             int ax = (w/2) + x;
  32.             int ay = y;
  33.             int bx = w+x;
  34.             int by = (int)(.374*(double)(h)+(double)(y));
  35.             int cx = (int)(.825*(double)(w)+(double)(x));
  36.             int cy = h+y;
  37.             int dx = (int)(.175*(double)(h)+(double)(x));
  38.             int dy = h+y;
  39.             int ex = x;
  40.             int ey = by;
  41.            
  42.             Polygon star = new Polygon();
  43.             g.setColor(Color.WHITE);
  44.             star.addPoint(ax,ay);
  45.             star.addPoint(83,ey);
  46.             star.addPoint(ex,ey);
  47.             star.addPoint(ex+53, ey+40);
  48.             star.addPoint(dx,dy);
  49.             star.addPoint(ax,dy-40);
  50.             star.addPoint(cx,cy);
  51.             star.addPoint(bx-53,ey+40);
  52.             star.addPoint(bx,by);
  53.             star.addPoint(117,ey);
  54.            
  55.            
  56.        
  57.             g.fillPolygon(star);
  58.        
  59.            
  60.             g.setColor(Color.GRAY);
  61.             g.drawRect(0, 0, 800, 400);
  62.        
  63.             }
  64.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement