aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Timers/Progress problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Timers/Progress problem" Watch "Timers/Progress problem" New topic
Author

Timers/Progress problem

Liat Barda
Greenhorn

Joined: Sep 17, 2003
Posts: 9
Hi
I got a problem related to the foloowing code.
I want to run this progress monitor - when i click on a button and then continue with the button action and close it in the end.
I see that the progress is crated and closed - but the progress is not displayed at all - and it also does not updated.
The test i did here - with the main works just fine - but when i call this from the button action listener - nothing happened.
Help please!!!

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;

public class TimeredProgressMonitor implements ActionListener {
public static final int MIN_VAL=1;
public static final int MAX_VAL=100;
public static final int TIMER_DELAY=500;
private ProgressMonitor progressMonitor;
private Timer t;
private int counter = 1;
public static int name=0;

public TimeredProgressMonitor(Component parentComponent, Object message, String note, int min, int max,int updateTimeMilisec) throws HeadlessException {
super();
name++;
progressMonitor = new ProgressMonitor(parentComponent, message, note, min, max);

progressMonitor.setMillisToPopup(updateTimeMilisec);
progressMonitor.setProgress(counter);

t = new Timer(updateTimeMilisec, this);
// t.start();
System.out.println("name="+name);
}
public TimeredProgressMonitor(Component parentComponent, int messageCode, String note, int min, int max,int updateTimeMilisec) throws HeadlessException {
super();
name++;
String message=UserMessages.getMessage(messageCode);
progressMonitor = new ProgressMonitor(parentComponent, message, note, min, max);
//progressMonitor.setMillisToPopup(updateTimeMilisec);
// progressMonitor.setProgress(counter);
t = new Timer(updateTimeMilisec, this);

System.out.println("name="+name);

}

public TimeredProgressMonitor(Component parentComponent, int messageCode, String note) throws HeadlessException {
this(parentComponent, messageCode, note, MIN_VAL, MAX_VAL,TIMER_DELAY);

}
public void startTimer()
{
t.start();
}
public void cancel()
{
System.out.println("cancel - name="+name);
progressMonitor.close();
progressMonitor=null;
t.stop();
}

public static void main(String[] args) {
UIManager.put("ProgressMonitor.progressText", "prog text");
//UIManager.put("ProgressMonitor.progressText","prog text");
try {
UserMessages.init();
} catch (BitBandConfigurationException e) {
e.printStackTrace();
}
TimeredProgressMonitor p=new TimeredProgressMonitor(new JFrame(),5003,"ttt");
p.startTimer();
// try {
// Thread.sleep(50000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// p.cancel();



}

public void actionPerformed(ActionEvent e) {
System.out.println("actionPerformed ");
System.out.println("name="+name);
if(progressMonitor!=null){
SwingUtilities.invokeLater(new ProgressMonitorTimerAction(this,progressMonitor,counter++));
}
else{
System.out.println("progressMonitor=null");
}
System.out.println("After invoke");

}

public void setProgress(int counter) {
System.out.println("name="+name);
progressMonitor.setProgress(counter);

}


}


liat barda
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Liat Barda
Greenhorn

Joined: Sep 17, 2003
Posts: 9
Thanks!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timers/Progress problem