public UserDelIFrame() {
super();
getContentPane().setLayout(null);
setIconifiable(true);//setIconifiable对于能够使 JInternalFrame 变成一个图标的用户而言,该属性必须为 true
setClosable(true);
setTitle("用户信息删除");
setBounds(100, 100, 300, 202);
Object[][] results = getFileStates(Dao.selectuser());
str = new String[] { "用户编号", "用户姓名", "密码" };
final JPanel panel_1 = new JPanel();
panel_1.setBounds(30, 125, 237, 37);
panel_1.setPreferredSize(new Dimension(0, 50));
getContentPane().add(panel_1);
final JButton button_2 = new JButton();
button_2.setText("删除");
panel_1.add(button_2);
button_2.addActionListener(new ActionListener() {//addActionListener将一个 ActionListener 添加到按钮中
@Override
public void actionPerformed(final ActionEvent e) {
int id = (Integer) table.getValueAt(table.getSelectedRow(), 0);
int i = Dao.Deluser(id);
if (i == 1) {
JOptionPane.showMessageDialog(null, "删除成功");
Object[][] results = getFileStates(Dao.selectuser());
DefaultTableModel model = new DefaultTableModel();
table.setModel(model);
model.setDataVector(results, str);
}
}
});
final JButton button_1 = new JButton();
button_1.setText("退出");
panel_1.add(button_1);
button_1.addActionListener(new CloseActionListener());
setVisible(true);//窗体可见
final JScrollPane scrollPane = new JScrollPane();//JScrollPane滚动条
scrollPane.setBounds(30, 10, 237, 110);
getContentPane().add(scrollPane);
scrollPane.setPreferredSize(new Dimension(237, 120));
table = new JTable(results, str);
TableColumn column = table.getColumn("用户姓名");//getColumn返回表中列的 TableColumn 对象
//TableColumn 表示 JTable 中列的所有属性
column.setPreferredWidth(90);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//AUTO_RESIZE_OFF不自动调整列的宽度
//setAutoResizeMode当调整表的大小时,设置表的自动调整模式
scrollPane.setViewportView(table);
//setViewportView 创建一个视口(如果有必要)并设置其视图
}
}