当前位置: 动力学知识库 > 问答 > 编程问答 >

How to use Timer correctly in Java?

问题描述:

I am new at Java and trying to make a sample application for an Airplane where you can see the Flight, Airstrip, Status and ETA. The code I am using is:

private Object[] getEta() {

Calendar cal = Calendar.getInstance();

int seconds = cal.get(Calendar.SECOND);

return new Object[] { 5 + new Random().nextInt(5) * 1000};

}

private class TimerListener implements ActionListener {

@Override

public void actionPerformed(ActionEvent e) {

DefaultTableModel model = (DefaultTableModel)table.getModel();

for (int i = model.getRowCount() -1; i >= 0; i--) {

Object[] row = getEta();

model.setValueAt(row[0], i, 3);

}try{

Thread.sleep(5000L);

} catch (InterruptedException e1) {

e1.printStackTrace();

}

}

}

My problem is how can i count ETA of each flight with a delay of 5 seconds between each flight and that while there are 10 flights?

分享给朋友:
您可能感兴趣的文章:
随机阅读: