Skip to main content

[JAVAHELP] I need help with ProgressMonitor

1 reply [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Java informační server

You have to start the for loop in actionPerformed method in separate
thread - this will help.

Eagle

Nigh, Gordon D FOR:EX wrote:

> I have been working for many hours trying to get ProgressMonitor to
> work, but with no success, so I need help.
>
> The following short program does nothing except display
> ProgressMonitor for a short period of time. Two buttons are
> implemented, one to quit the program and the other to execute a loop.
> The ProgressMonitor monitors the progress of the loop. The
> ProgressMonitor dialog pops up but nothing shows up in the dialog.
> The title is not there and the progress bar does not show up.
> However, the ProgressMonitor does close when the loop is finished.
>
> Can anyone help?
>
> Thanks in advance.
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> class Test extends JFrame implements ActionListener {
> private JButton runButton = new JButton("Run"),
> quitButton = new JButton("Quit");
>
> public ProgressMonitor progressMonitor;
>
> public static void main(String[] args) {
> new Test();
> }
>
> private Test() {
> super("Test Progress Monitor");
> getContentPane().setLayout(new FlowLayout());
> getContentPane().add(runButton);
> runButton.addActionListener(this);
> getContentPane().add(quitButton);
> quitButton.addActionListener(this);
> pack();
> setVisible(true);
> }
>
> public void actionPerformed(ActionEvent event) {
> if (event.getSource() == runButton) {
> progressMonitor = new ProgressMonitor(Test.this,
> "Test progress monitor", null, 1, 100);
> progressMonitor.setMillisToDecideToPopup(0);
> progressMonitor.setMillisToPopup(0);
> progressMonitor.setProgress(0);
> for (int i = 1; i <= 100; i ++) {
> try {Thread.sleep(10);}
> catch(InterruptedException e) {}
> progressMonitor.setProgress(i);
> }
> } else if (event.getSource() == quitButton) {
> dispose();
> System.exit(0);
> }
> repaint();
> }
> }
>
> ********************************************************************************
>
>
> You may leave the list at any time by sending message with no subject
> and "SIGNOFF JAVAHELP-INTEREST" in the body to LISTSERV@JAVA.SUN.COM.
> Archives are available at
> http://archives.java.sun.com/archives/javahelp-interest.html. Submit
> bug reports at http://java.sun.com/cgi-bin/bugreport.cgi.
>

********************************************************************************

You may leave the list at any time by sending message with no subject and
"SIGNOFF JAVAHELP-INTEREST" in the body to LISTSERV@JAVA.SUN.COM. Archives
are available at http://archives.java.sun.com/archives/javahelp-interest.html.
Submit bug reports at http://java.sun.com/cgi-bin/bugreport.cgi.
[att1.html]