Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import java.awt.*;
- public class squares extends JFrame
- {
- public void paint (Graphics g) //paint class
- {
- super.paint(g);
- g.setColor(Color.CYAN); //setting background color
- g.fillRect(0,0,200,300); //filling background with color cyan
- SquareMethod(g,50,50,20,20); //calling method
- g.setColor(Color.BLACK);
- g.drawLine(50,50,150,150); //drawing black diagonal line
- }
- public static void SquareMethod(Graphics g, int x, int y, int w, int h) //method to make the squares
- {
- for (int i=1;i<=5;i++)
- {
- g.setColor(Color.RED);
- g.drawRect(x,y,20*i,20*i);
- }
- }
- public static void main (String [] args) //frame
- {
- squares app = new squares();
- app.setSize(200,300);
- app.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment