/
boardObject.java
39 lines (33 loc) · 1.11 KB
/
boardObject.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
39
import java.awt.*;
import java.awt.image.*;
public class boardObject {
static final int O_IMG = 0, O_COL = 1;
Color objColour;
Image objImage;
int style;
int xcoord, ycoord;
public boardObject(Color c) {
this.objColour = c;
this.style = O_COL;
}
public boardObject(Image i) {
this.objImage = i;
this.style = O_IMG;
}
public void setCoords(Dimension d) { xcoord = d.width; ycoord = d.height; }
public void setCoords(int x, int y) { xcoord = x; ycoord = y; }
public void drawObject(Graphics g, int w, int h, ImageObserver i) { drawObject(g,xcoord,ycoord,w,h,i); }
public void drawObject(Graphics g, int w, int h) { drawObject(g,xcoord,ycoord,w,h,null); }
public void drawObject(Graphics g, int x, int y, int w, int h) { drawObject(g,x,y,w,h,null); }
public void drawObject(Graphics g, int x, int y, int w, int h, ImageObserver i) {
if (style == O_IMG) {
// paint image
g.drawImage(objImage, x*w, y*h, w, h, i);
} else {
// paint square
g.setColor(objColour);
g.fillRect(x*w,y*h,w,h);
}
}
public String toString() {return objColour.toString();}
}