Read the following article regarding usage of threads
in swing app.

http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html

cheers..
Samir


--- cerqueira <[EMAIL PROTECTED]> wrote:
> 
> Hi,
> 
> I would appreciate if someone could help me with the
> following doubt:
> 
> Scenario:
> -------------
> I made a form using java swing, which has some
> buttons.
> To all the buttons I added an ActionListener - which
> will implement the
> actionPerformed() function.
> 
> Problem:
> ------------
> Some of the actions performed when the user presses
> one button take some
> minutes (not too much), however I thought of
> showing JOptionPane.showMessageDialog() presenting
> the message "Processing
> task" while the user waits for the results...
> 
> Tried solution:
> -------------------
> I made a class which estends Thread:
> 
> public class OperationProgressThread extends Thread
> {
> 
>    private static JOptionPane jOptionPane;
> 
>    public OperationProgressThread ()
>    {
>       jOptionPane = new JOptionPane();
>    }
> 
>    public void run()
>    {
>       jOptionPane.showMessageDialog( null, "Please
> wait...", "",
> JOptionPane.INFORMATION_MESSAGE);
>    }
> }
> 
> Then in the class where I defined the form, i create
> a new instance of
> OperationProgressThread and invoke the start() and
> stop()
> methods in the beginning and at the end
> (respectively) of the action to
> perform when the button is pressed:
> 
>    OperationProgressThread  thread = new
> OperationProgressThread();
> 
>     doImport.setPreferredSize(new
> java.awt.Dimension(80, 27));
>     doImport.setText("Import");
>     doImport.addActionListener(new
> java.awt.event.ActionListener() {
>          public void
> actionPerformed(java.awt.event.ActionEvent evt) {
>             doImportActionPerformed(evt);
>          }
>       }
>       );
> 
>    /**
>     * The doImportActionPerformed method in this
> class
>     * is called when the user presses the "Import"
> button.
>     */
>    private void
> doImportActionPerformed(java.awt.event.ActionEvent
> evt)
>    {
>       thread start();
>       boolean bRetVal = false;
>       try
>       {
>          bRetVal = dbIntUser.cmdImportClick(
> sSelectedInterface );
>          System.out.println( "cmdImportClick
> returned " + bRetVal );
>       }
>       catch ( ComJniException cje ) {
> jOptionPane1.showMessageDialog( null,
> cje.getMessage(), "Exception",
> JOptionPane.ERROR_MESSAGE); }
>       catch ( Exception e )         {
> jOptionPane1.showMessageDialog( null,
> e.getMessage(), "Exception",
> JOptionPane.ERROR_MESSAGE);   }
>    }
>    thread.stop();
> }
> 
> 
> The problem is that this window is only poped up
> when the results are
> shown.... so I have no clue of what should I do...
> Thanks in advance.
> 
> 
> 
> _______________________________________________
> Advanced-swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/advanced-swing


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to