这是我画图使用的类:
[Java] 纯文本查看 复制代码 import javax.swing.*;
import java.awt.*;
public class Xianshimianban extends JPanel {
private int[][] xianshishuzu=null;
public Xianshimianban()
{
xianshishuzu=new int[50][50];
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
xianshishuzu[i][j]=0;
}
}
}
public void paint (Graphics g)
{
super.paint(g);
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
g.setColor(Color.WHITE);
g.drawRect(i*16,j*16,16,16);
if(xianshishuzu[i][j]==0)
{
g.setColor(Color.LIGHT_GRAY);
g.fill3DRect((i*16+1),(j*16+1),15,15,false);
}else{
g.setColor(Color.BLACK);
g.fill3DRect((i*16+1),(j*16+1),15,15,true);
}
}
}
}
public void clean()
{
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
xianshishuzu[i][j]=0;
}
}
}
public void setgaibian(int x, int y)
{
xianshishuzu[x][y]=1;
this.repaint();
}
public int[][] getXianshishuzu() {
return xianshishuzu;
}
public void setXianshishuzu(int[][] xianshishuzu) {
this.xianshishuzu = xianshishuzu;
this.repaint();
}
}
|