-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLegosP1.java
More file actions
53 lines (46 loc) · 1.32 KB
/
LegosP1.java
File metadata and controls
53 lines (46 loc) · 1.32 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
package legoMania;
import javax.swing.*;
import java.awt.*;
public class LegosP1 extends JPanel {
static final long serialVersionUID = 42L;
@Override
public void paintComponent(Graphics g) {
int startX = 20;
int startY = 260;
int legoWidth = 50;
int legoHeight = 20;
int baseLength = 10;
int arcWidth = 2;
int arcHeight = 2;
Color redLego = Color.RED;
Color blueLego = Color.BLUE;
super.paintComponent(g);
//draw Rectangle
for (int i=baseLength;i>=1;i--) {
Color color = redLego;
for (int j = 0;j<i;j++) {
g.setColor(color);
if(color == redLego)
color = blueLego;
else
color = redLego;
int gap=(baseLength-i)*(legoWidth/2);
g.fillRoundRect(gap+(j*legoWidth)+startX, startY-(baseLength-i)*legoHeight, legoWidth, legoHeight, arcWidth, arcHeight);
}
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(550,325);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Abunaw's LEGOS Block");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
LegosP1 d = new LegosP1();
JPanel panel = new JPanel();
panel.add(d);
frame.add(panel);
frame.setSize(550,325);
frame.setVisible(true);
}
}