2 younglee2013 younglee2013 于 2014.08.30 20:07 提问

Type CENTER cannot be resolved or is not a field

我刚学java,求助:编译报错:Type CENTER cannot be resolved or is not a field
报错代码为: getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(p2, BorderLayout.SOUTH);
getContentPane().add(new JScrollPane(tbl), BorderLayout.CENTER);
具体全部代码如下:
import javax.swing.*;
import java.awt.*;
class mWin extends JFrame {
JTable tbl;
Object data[][];
Object title[] = {"学号", "姓名", "性别", "出生年月"};
final int ROW = 5;
final int COL = 4;
JPanel p1, p2;
public mWin(String s) {
super(s);
data = new Object[ROW][COL];
for (int i = 0; i < ROW; i++) {
for (int j = 0; j < COL; j++) {
data[i][j] = "";
}
}
tbl = new JTable(data, title);
p1 = new JPanel();
p2 = new JPanel();
p1.add(new JLabel("学生基本信息"));
getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(p2, BorderLayout.SOUTH);
getContentPane().add(new JScrollPane(tbl), BorderLayout.CENTER);
setSize(240, 200);
setVisible(true);
validate();
}
}
public static void main(String[] args) {
new mWin("表格的例子");
}
}

1个回答

u012882394
u012882394   2014.08.30 22:15

代码没问题,我运行过了,可以

younglee2013
younglee2013 但是我在我的eclipse上就不行,我把错误截图吧!
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!