问题描述
- 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("表格的例子");
}
}
解决方案
代码没问题,我运行过了,可以
时间: 2024-11-02 09:30:53