liangm20

Unit 4: Design

Oct 26th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import java.awt.*;
  3. public class squares extends JFrame
  4. {
  5. public void paint (Graphics g) //paint class
  6. {
  7. super.paint(g);
  8. g.setColor(Color.CYAN); //setting background color
  9. g.fillRect(0,0,200,300); //filling background with color cyan
  10. SquareMethod(g,50,50,20,20); //calling method
  11. g.setColor(Color.BLACK);
  12. g.drawLine(50,50,150,150); //drawing black diagonal line
  13. }
  14. public static void SquareMethod(Graphics g, int x, int y, int w, int h) //method to make the squares
  15. {
  16. for (int i=1;i<=5;i++)
  17. {
  18. g.setColor(Color.RED);
  19. g.drawRect(x,y,20*i,20*i);
  20. }
  21. }
  22. public static void main (String [] args) //frame
  23. {
  24. squares app = new squares();
  25. app.setSize(200,300);
  26. app.setVisible(true);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment