D:\chengji>java Chess
Exception in thread "main" java.lang.NullPointerException
at Chess.go(Chess.java:19)
at Chess.main(Chess.java:26)
不过没改出来~~
Exception in thread "main" java.lang.NullPointerException
at Chess.go(Chess.java:19)
at Chess.main(Chess.java:26)
不过没改出来~~
import java.awt.*;
public class Chess extends JFrame {
JFrame jf;
JButton jb[][]; Container c;
JPanel jp;
void go() {
jf = new JFrame("Chess Game");
c = jf.getContentPane();
jb = new JButton[19][19];
//jb=null;
jp = new JPanel();
c.add(jp);
jp.setLayout(new GridLayout(19, 19));
for (int i = 0; i < 19; i++)
for (int j = 0; j < 19; j++) {
jb[i][j] = new JButton();
jp.add(jb[i][j]);
}
jf.setSize(600, 600);
jf.show();
}
public static void main(String[] args) {
Chess chess = new Chess();
chess.go();
}
}
我是太烂了
没想出来~~
jb = new JButton[19][19];
jb[i][j] = new JButton();
有什么区别啊?
还有这又用go()这个函数有必要吗?
直接用Chess()不行吗?