类Web_Reader是一个摇摆工作者,他是" doInBackground"在下面。为什么" this.setProgress"不解雇" propertyChange"方法?从我所读到的,我已经正确实施。
public class Web_Reader extends SwingWorker implements ACL_Form_Fetcher, PropertyChangeListener {}
@Override
protected ACL_Form_Collection doInBackground() throws Exception {
// setProgress(0);
ACL_Form_Collection data = new ACL_Form_Collection();
double numberOfForms = 0;
ArrayList<String> input = this.readFromWeb(this.ticketNumber);
double inputs = (double) input.size();
while (numberOfForms <input.size() && !isCancelled()) {
for (int i = 0; i < input.size(); i++) {
int v = (int) (((double) numberOfForms / inputs) * 100);
this.setProgress(v);
Thread.sleep(5000);
String get = input.get(i);
//Create Form
ACL_Form form = this.getForm(i, get);
data.add(form);
//Callables are added to executor and execution begins
// p.setNote(message);
++numberOfForms;
}
this.setProgress(100);
//shut down executor here
}
return data;
}
这是位于&#34; Web_Reader&#34;中的属性更改方法。
@Override
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("evt= "+evt);
if ("progress" == evt.getPropertyName()) {
int progress = (Integer) evt.getNewValue();
progressMonitor.setProgress(progress);
String message = String.format("Completed %d%%.\n", progress);
progressMonitor.setNote(message);
System.out.println("Message= "+message);
if (progressMonitor.isCanceled() || ACL_Maker.executor.isDone()) {
Toolkit.getDefaultToolkit().beep();
if (progressMonitor.isCanceled()) {
ACL_Maker.executor.cancel(true);
// taskOutput.append("Task canceled.\n");
} else {
// taskOutput.append("Task completed.\n");
}
//startButton.setEnabled(true);
}
}
}