Solved

Process JDialog

Posted on 2004-07-30
9
315 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
  • 3
  • 2
  • 2
9 Comments
 
LVL 92

Accepted Solution

by:
objects earned 50 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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 50 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven project error 5 54
java jdbc batch example 8 31
eclipse console opening separately 2 16
printf performancy 11 31
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now