Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

thread v. timer in ProgressMonitor subclass



Comrades,

I am trying to implement a ExecutionProgressMonitor". It looks like this:

public class ExecutionProgressMonitor extends ProgressMonitor implements ActionListener {
private int counter = 0;
private javax.swing.Timer timer;
private Model _model;

    public ExecutionProgressMonitor(Model mod) {
        super(null, "Running...", "Init...", 0, 100);
_model = mod;
timer = new javax.swing.Timer(5, this);
timer.start();
}


public int getModelProgress() {return _model.getprogress(); } // a jni call
public void actionPerformed(ActionEvent e) {SwingUtilities.invokeLater(new Update()); }

// embedded helper class

    class Update implements Runnable {
public void run() {
System.out.println("new Update");
if(isCanceled() || counter > 98) {
// stop the model and kill the monitor
model.halt();
counter = getMaximum(); // set to finished state
close();
}
else {
counter = getModelProgress();
setProgress(counter);
setNote(counter + "% complete");
}
}
}


}


I call it just before the execution that it is going to monitor is launched, like his:

model.setup();
ExecutionProgressMonitor epmon = new ExecutionProgressMonitor(model); // the model is what we monitor
model.run();// this can take a while, its what I want to monitor.

So, my problem is that I never see my monitor, no matter how long the execution process takes. The Timer thing works, because I get a bunch of my Update objects created, but it all happens AFTER the call to model.run(), which is not very useful. Its as though the Timer is somehow not getting started up or something.

Anyone know why what I have won't work, and what to do differently?



"An ocean without its unnamed monsters would be like a completely
dreamless sleep."
— John Steinbeck


Paul Archibald



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.