-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
63 lines (55 loc) · 1.27 KB
/
Copy pathBlock.java
File metadata and controls
63 lines (55 loc) · 1.27 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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import javax.swing.JComponent;
public class Block extends JComponent
{
private Rectangle rect;
private double absX, absY, relX, relY;
private Color color = Color.RED;
public Block(int x, int y, int w, int h, Color c)
{
this.setSize(new Dimension(w, h));
this.setLocation(x,y);
absX = x;
absY = y;
color = c;
rect = new Rectangle(0,0,w,h);
}
public Color getColor() {return color;}
public Rectangle getRect()
{
return new Rectangle((int)(absX + relX), (int)(absY + relY), this.getWidth(), this.getHeight());
}
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
g2.setColor(color);
g2.fill(rect);
g2.draw(rect);
}
public void setPosition(int relX, int relY)
{
this.setLocation((int)(absX + relX), (int)(absY + relY));
}
public Point getPosition()
{
return(new Point((int)(absX + relX), (int)(absY + relY)));
}
public int getRelX()
{
return (int)relX;
}
public int getRelY()
{
return (int)relY;
}
public void setObjectColor(Color c)
{
color = c;
}
}