-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawingPanel.java
More file actions
104 lines (92 loc) · 2.4 KB
/
Copy pathDrawingPanel.java
File metadata and controls
104 lines (92 loc) · 2.4 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import javax.swing.*;
import java.awt.*;
/**
* Te-Feng (Dylan) Pan
* CS 162 - Lab 7B: Recursive Shapes
* This class creates a panel that example shapes are
* drawn on. the main is in RecursiveShapes.java
*/
public class DrawingPanel extends JPanel
{
private JCheckBox[] checkBoxArray; // Check box array
/**
* Constructor
*/
public DrawingPanel(JCheckBox[] cbArray)
{
// Reference the check box array.
checkBoxArray = cbArray;
// Set this panel's background color to white.
setBackground(Color.WHITE);
// Set the preferred size of the panel.
setPreferredSize(new Dimension(400, 400));
}
/**
* paintComponent method
*/
public void paintComponent(Graphics g)
{
// Call the superclass paintComponent method.
super.paintComponent(g);
// Draw the selected shapes.
if (checkBoxArray[0].isSelected())
{
g.setColor(Color.BLACK);
drawCircles(g, 10, 5, 300);
}
if (checkBoxArray[1].isSelected())
{
g.setColor(Color.GREEN);
drawRect(g, 10, 100, 150);
}
if (checkBoxArray[2].isSelected())
{
g.setColor(Color.BLUE);
drawOval(g, 150, 75, 150);
}
/*if (checkBoxArray[3].isSelected())
{
g.setColor(Color.BLACK);
g.drawOval(40, 155, 75, 50);
}
if (checkBoxArray[4].isSelected())
{
g.setColor(Color.BLUE);
g.fillOval(200, 125, 75, 50);
}
if (checkBoxArray[5].isSelected())
{
g.setColor(Color.BLACK);
g.drawArc(200, 40, 75, 50, 0, 90);
}
if (checkBoxArray[6].isSelected())
{
g.setColor(Color.GREEN);
g.fillArc(100, 155, 75, 50, 0, 90);
}*/
}
private void drawCircles(Graphics g, int n, int topXY, int size)
{
if (n > 0)
{
g.drawOval(topXY, topXY, size, size);
drawCircles(g, n - 1, topXY + 15, size - 30);
}
}
private void drawRect(Graphics g, int n, int topXY, int size)
{
if (n > 0)
{
g.drawRect(topXY, topXY, size, size);
drawRect(g, n - 1, topXY + 10, size - 30);
}
}
private void drawOval(Graphics g, int n, int topXY, int size)
{
if (n > 0)
{
g.drawOval(topXY, topXY, size, size);
drawOval(g, n - 1, topXY + 10, size - 50);
}
}
}