?
Solved

Process JDialog

Posted on 2004-07-30
9
Medium Priority
?
329 Views
Last Modified: 2006-11-17
Does anyone have a quick class to produce a JDialog saying processing or something along that lines, to be displayed and automatically disposed of while a procedure is processing... leave the main JFrame process anyway while the JDialog is being displayed and then be automatically disposed of.
0
Comment
Question by:dwaneos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
9 Comments
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 11675181
Have a look at ProgressMonitor class.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11675183
0
 
LVL 92

Expert Comment

by:objects
ID: 11675185
If you want to build it yourself then the SwingWorker class makes it fairly straightforward.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dwaneos
ID: 11675370
I don't get it... how does the progessMonitor know when to dispose of itself when the process has stopped.
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 200 total points
ID: 11675398
Does this help:

http://mail.phys-iasi.ro/Library/Computing/jfc_unleashed/ch21.htm

---------------

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

/**
 * An application that displays a ProgressMonitor
 * when the 'start' button is pressed. A simple
 * 'operation' to update the monitor
 *
 * @author Mike Foley
 **/

public class ProgressTest extends Object {

    /**
     * Application entry point.
     * Create the splash window, and display it.
     *
     * @param args Command line parameter. Not used.
     **/
    public static void main( String args[] ) {

        //
        // Create a frame with a single button in it.
        // When the button is pressed, a thread is spawned
        // to run out sample operation.
        //
        JFrame frame = new JFrame( "ProgressMonitor Test" );
        JButton button = new JButton( "Start" );
        frame.getContentPane().add( button, BorderLayout.CENTER );

        //
        // Create a ProgressMonitor. This will be started
        // when the button is pressed.
        //
        int min = 0;
        int max = 100;
        String[] message = new String[2];
        message[0] = "Performing Operation.";
        message[1] = "This may take some time...";
        final ProgressMonitor monitor = new  ProgressMonitor( frame,
                                                      message,
                                                      "Iteration",
                                                      min,
                                                      max );

        //
        // This is our sample operation.
        //
        final Runnable runnable = new Runnable() {
            public void run() {
                int sleepTime = 500;
                for( int i = 1; i < 100; i++ ) {
                    try {                        
                        monitor.setNote( "Iteration " + i );
                        monitor.setProgress( i );
                        if( monitor.isCancelled() ) {
                            monitor.setProgress( 100 );
                            break;
                        }
                        Thread.sleep( sleepTime );
                    }  catch( InterruptedException dontcare ) {                    
                    }
                }
                monitor.close();
            }
        } ;
       
        button.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
                //
                // Run the operation in its own thread.
                //
                Thread thread = new Thread( runnable );
                thread.start();

            }
        }  );
       
        //
        // Show the frame.
        //
        frame.pack();
        frame.setVisible( true );

    }  // main

}  // ProgressTest
0
 

Author Comment

by:dwaneos
ID: 11675510
What about the isCancelled()?
Where does that fit in to all of it?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11675872
There is a "Cancel" button on the progressMonitor dialog...

if the user presses it, isCancelled() returns true...
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question