java paintComponent调用其它类的变量________在线等
五子棋程序,其中调用paintComponent来绘制棋盘和棋子,但是其参数只有一个graphic,在另一个类中有一个二维数组变量,不能传递该参数,如何调用该变量?cla...
五子棋程序,其中调用paintComponent来绘制棋盘和棋子,但是其参数只有一个graphic,在另一个类中有一个二维数组变量,不能传递该参数,如何调用该变量?
class NewPanel extends JPanel
{
private static final long serialVersionUID = 1L;
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
for(int i = 0 ; i < 15 ; i++)
{
g.drawLine(10, 10+20*i, 290, 10+20*i);
g.drawLine(10+20*i, 10, 10+20*i, 290);
}
}
} 展开
class NewPanel extends JPanel
{
private static final long serialVersionUID = 1L;
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
for(int i = 0 ; i < 15 ; i++)
{
g.drawLine(10, 10+20*i, 290, 10+20*i);
g.drawLine(10+20*i, 10, 10+20*i, 290);
}
}
} 展开
展开全部
定义一个二维数组,再定义一个构造函数就可以把二维数组传进来了。
程序如下:
import java.awt.Graphics;
import javax.swing.JPanel;
class NewPanel extends JPanel
{
private static final long serialVersionUID = 1L;
int a[][];
NewPanel(int b[][]){
this.a=b;
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
for(int i = 0 ; i < 15 ; i++)
{
g.drawLine(10, 10+20*i, 290, 10+20*i);
g.drawLine(10+20*i, 10, 10+20*i, 290);
}
}
}
程序如下:
import java.awt.Graphics;
import javax.swing.JPanel;
class NewPanel extends JPanel
{
private static final long serialVersionUID = 1L;
int a[][];
NewPanel(int b[][]){
this.a=b;
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
for(int i = 0 ; i < 15 ; i++)
{
g.drawLine(10, 10+20*i, 290, 10+20*i);
g.drawLine(10+20*i, 10, 10+20*i, 290);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询