Solved

Process JDialog

Posted on 2004-07-30
9
326 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 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

717 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