-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shapes
33 lines (27 loc) · 1011 Bytes
/
Shapes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//Fid 4.25: Shapes.java
//Drawing a cascade of shapes based on the user's choice.
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class Practice410 extends JPanel {
// draws a cascade of shapes starting from the top-left corner
public void paintComponent(Graphics g)
{
super.paintComponent(g);
for (int i = 0; i < 10; i++)
{
g.drawRect(10 + i * 10, 10 + i * 10,
50 + i * 10, 50 + i * 10);
g.drawOval(240 + i * 10, 10 + i * 10,
50 + i * 10, 50 +i * 10);
}
}
public static void main (String[] args) {
Practice410 panel = new Practice410(); //create the panel
JFrame application = new JFrame(); //creates a new JFrame
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel);
application.setSize(500, 290);
application.setVisible(true);
}
}//end class Shapes