我现在的需求是,通过点击上面不同的按钮,下方出现对应的表格。
界面程序代码:首先初始化了一个表格
// 图表窗口
public void tableInformation() {
JPanel toolBar = new JPanel();
toolBar.add(this.loadFileBtn);
toolBar.add(this.transferBtn);
toolBar.add(this.selectBtn);
toolBar.add(this.functionNumBtn);
toolBar.add(this.scoreBtn);
toolBar.add(this.noScoreBtn);
this.add(toolBar, BorderLayout.NORTH);
this.loadFileBtn.addActionListener(this);
this.transferBtn.addActionListener(this);
this.selectBtn.addActionListener(this);
this.functionNumBtn.addActionListener(this);
this.scoreBtn.addActionListener(this);
this.noScoreBtn.addActionListener(this);
this.tableModel = new DefaultTableModel(new UserList().userInfo, new UserList().titles);
this.table = new JTable(this.tableModel);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setPreferredScrollableViewportSize(new Dimension(150, 0));
table.getTableHeader().setReorderingAllowed(false);
table.enable(false);
JScrollPane scr = new JScrollPane(this.table);
this.add(scr, BorderLayout.CENTER);
this.remove(scr);
//
while (this.tableModel.getRowCount() > 0) {
this.tableModel.removeRow(this.tableModel.getRowCount() - 1);
}
}
现在我想做的是:当点击“统计操作数”按钮时,会出现另一个表格样式
按钮代码:
else if (e.getSource() == this.functionNumBtn) {
//这里如何写?
}
补充数据源代码:
class UserList extends AbstractTableModel {
public String[] titles = { "username", "udate", "utime", "tcode" };
public Object[][] userInfo = {}; //
public int getRowCount() {
return 0;
}
public int getColumnCount() {
return 0;
}
//
@Override
public Object getValueAt(int arg0, int arg1) {
return null;
}
}
请教如何做?(代码中的空格部分)