抱歉,这是我正在尝试使用JProgressBar的任务的地方:
class Task extends SwingWorker<Void, Void> {
@Override
public Void doInBackground() {
for (int i = 0; i <= 100; i++) {
doTheWork();//where work happens
System.out.println(i);
jProgressBar1.setValue(i);
}
return null;
}
@Override
public void done() {
Toolkit.getDefaultToolkit().beep();
jButton1.setEnabled(true);
setCursor(null); //turn off the wait cursor
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jButton1.setEnabled(false);
setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
//Instances of javax.swing.SwingWorker are not reusuable, so
//we create new instances as needed.
task = new Task();
task.addPropertyChangeListener(this);
task.execute();
}
问题是task.addPropertyChangeListener(this);抛出错误,因为我的主类扩展了JFrame并且无法实现ActionListener,PropertyChangeListener,因为按照oracle示例,它不是抽象的。我不明白为什么。
错误是没有为ActionListner重写方法,必须添加:
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}