pane.java

来自「此游戏仅是用来使Java初学者掌握Java基础语法和面向对象的编程思想。」· Java 代码 · 共 59 行

JAVA
59
字号
import java.awt.*;

//每个图形由四个方格所组成,Pane对象表示图形中的每一个方格
public class Pane
{
	//表示方格的左上角坐标
	private int xpos;
	private int ypos;
	//填充方格的颜色
	private Color color;
	
	public Pane(Color color)
	{
		this.color=color;	
	}
	
	//调整方格的位置
	public void setPlace(int xpos,int ypos)
	{
		this.xpos=xpos;
		this.ypos=ypos;	
	}
	//绘制方格
	public void paint(Graphics g)
	{
		//先画方格
		g.setColor(color);
		g.fillRect(xpos,ypos,20,20);

		//后画方格边框
		g.setColor(Color.white);
		g.drawRect(xpos,ypos,20,20);
	}
	
	//返回方格的坐标
	public int getX()
	{
		return this.xpos;
	}
	public int getY()
	{
		return this.ypos;
	}
	
	//返回方格在二维数组中的下标值
	public int[] getCellSuffix()
	{
		int t[]=new int[2];
		t[0]=ypos/20;
		if(t[0]<0){	t[0]=0;	}
		if(t[0]>19){	t[0]=19;	}
		
		t[1]=xpos/20;
		if(t[1]<0){	t[1]=0;	}
		if(t[1]>9){	t[1]=9;	}
		
		return t;		
	}
}

⌨️ 快捷键说明

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