📄 pane.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 + -