boardobject.java

来自「用java写的一个强化学习程序」· Java 代码 · 共 40 行

JAVA
40
字号
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();}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?