当前位置: 代码迷 >> J2SE >> 为何JTable表单和里面的数据都显示不出来
  详细解决方案

为何JTable表单和里面的数据都显示不出来

热度:4036   发布时间:2013-02-25 00:00:00.0
为什么JTable表单和里面的数据都显示不出来
[align=center][/align][code=Java][/code]public class StudentManger extends JFrame {

private JPanel contentPane;
private JTable table;
private JTextField studNo;
private JTextField studName;
private JTextField studAge;
private JTextField studSex;
private JTextField studClass;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Object[][] playerInfo;
private JPanel panel;
private String[] columnNames;
private JTable table_1;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
StudentManger frame = new StudentManger();
frame.setVisible(true); 
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public StudentManger() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 613, 468);
this.connDB();
System.out.println("数据库连接成功");
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);



JLabel lblNewLabel = new JLabel("学号:");
lblNewLabel.setBounds(10, 10, 57, 18);
contentPane.add(lblNewLabel);

studNo = new JTextField();
studNo.setBounds(50, 9, 106, 21);
contentPane.add(studNo);
studNo.setColumns(10);

JLabel lblNewLabel_1 = new JLabel("姓名:");
lblNewLabel_1.setBounds(178, 12, 45, 15);
contentPane.add(lblNewLabel_1);

studName = new JTextField();
studName.setBounds(233, 9, 106, 21);
contentPane.add(studName);
studName.setColumns(10);

JLabel label = new JLabel("性别:");
label.setBounds(366, 12, 45, 15);
contentPane.add(label);

studAge = new JTextField();
studAge.setBounds(421, 9, 106, 21);
contentPane.add(studAge);
studAge.setColumns(10);

JLabel lblNewLabel_2 = new JLabel("年龄:");
lblNewLabel_2.setBounds(10, 38, 57, 15);
contentPane.add(lblNewLabel_2);

studSex = new JTextField();
studSex.setBounds(50, 38, 106, 21);
contentPane.add(studSex);
studSex.setColumns(10);

JLabel lblNewLabel_3 = new JLabel("班级:");
lblNewLabel_3.setBounds(178, 37, 54, 15);
contentPane.add(lblNewLabel_3);

studClass = new JTextField();
studClass.setBounds(233, 40, 106, 21);
contentPane.add(studClass);
studClass.setColumns(10);

JButton btnAdd = new JButton("增加");
btnAdd.setBounds(22, 80, 93, 32);
contentPane.add(btnAdd);

JButton btnDelete = new JButton("删除");
btnDelete.setBounds(137, 80, 93, 32);
contentPane.add(btnDelete);

JButton btnUpdate = new JButton("修改");
btnUpdate.setBounds(252, 80, 93, 32);
contentPane.add(btnUpdate);

JButton btnSelete = new JButton("查询");
btnSelete.setBounds(367, 80, 93, 32);
contentPane.add(btnSelete);

JButton btnShow = new JButton("显示");
btnShow.setBounds(482, 80, 93, 32);
contentPane.add(btnShow);


}

public void display() {// 显示所有学生的基本信息
int i = 0;
int j = 0;
List al = new ArrayList();
try {
rs = stmt.executeQuery("select * from studInf");
while (rs.next()) { // 找出表中的记录数赋给i
al.add(rs.getString("studNo"));
al.add(rs.getString("studName"));
al.add(rs.getString("studAge"));
al.add(rs.getInt("studSex"));
al.add(rs.getString("studClass"));
  相关解决方案