所以我有这个帖子:
public static class Update implements Runnable{
public void run() {
Timer tm;
tm = new Timer(5000, new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
Clienti cl = new Clienti();
cl.populateTable();
}
});
tm.start();
}
}
我从另一个包中运行它(我做这个实验)。但是,在尝试程序时,似乎是populateTable();函数只在Update类中工作?我已经尝试在Clienti类中创建这个类并且它完美地工作,但是这似乎有一些问题。我做错了吗?
这是populateTable()方法:
public void populateTable(){
MyQuery mq = new MyQuery();
ArrayList<GetClass> list = mq.BindTable();
String[] columnName = {"ID","Picture","Name","Age","Sex"};
Object[][] rows = new Object[list.size()][5];
int i;
for(i = 0; i < list.size(); i++){
rows[i][0] = list.get(i).getId();
if(list.get(i).getPicture() != null){
ImageIcon image = new ImageIcon(new ImageIcon(list.get(i).getPicture()).getImage()
.getScaledInstance(50, 50, Image.SCALE_SMOOTH) );
rows[i][1] = image;
}
else{
rows[i][1] = null;
}
rows[i][2] = list.get(i).getName();
rows[i][3] = list.get(i).getAge();
rows[i][4] = list.get(i).getSex();
}
TheModel model = new TheModel(rows, columnName);
table.setModel(model);
table.setRowHeight(50);
table.getColumnModel().getColumn(4).setPreferredWidth(150);
答案 0 :(得分:0)
与Luminous_Dev聊天后,他想出了答案。我将此添加到更新线程:
private Clienti clienti;
public Update(Clienti clienti){
this.clienti = clienti;
}
并且还改变了
Clienti cl = new Clienti();
cl.populateTable();
clienti.populateTable();
并添加&#34;此&#34;在构造函数内部,我创建了线程。