⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pane.java

📁 此游戏仅是用来使Java初学者掌握Java基础语法和面向对象的编程思想。
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -