Solved

Process JDialog

Posted on 2004-07-30
9
312 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
Comment Utility
Have a look at ProgressMonitor class.
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
If you want to build it yourself then the SwingWorker class makes it fairly straightforward.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:dwaneos
Comment Utility
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
Comment Utility
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
Comment Utility
What about the isCancelled()?
Where does that fit in to all of it?
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
There is a "Cancel" button on the progressMonitor dialog...

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now