-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brick.java
38 lines (33 loc) · 839 Bytes
/
Brick.java
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
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class Brick extends JPanel implements Observer {
//Inherited method from Observer
private int width, height, posX, posY;
private boolean showBrick = true;
public Brick(int posX, int posY, int width, int height) {
this.width = width;
this.height = height;
this.posX = posX;
this.posY = posY;
// o.addObserver(this);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(showBrick) {
g.setColor(Color.cyan);
g.drawRect(posX, posY, width, height);
g.setColor(Color.magenta);
g.fillRect(posX, posY, width, height);
}
}
public Rectangle getBounds() {
return new Rectangle(posX,posY,width,height);
}
@Override
public void update() {
showBrick=false;
repaint();
}
}