*
The moose likes Beginning Java and the fly likes using threads or there's another way? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "using threads or there Watch "using threads or there New topic
Author

using threads or there's another way?

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
in a swing standalone app i want a message to appear for a few seconds confirming user did deleted something
i'm using this code:

is there a better/smoother way of doing this?

TiA


java amateur
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

Actually, once your swing application has been displayed, you are not allowed to access any of the components from anything that is not the event dispatching thread. With the exception of a few methods, like repaint(), it is not thread safe to do so.

Having a separate thread to handle the timing for changing the visibility is fine, but it is not allowed to directly manipulate the component. Take a look at the invokeLater() method of the SwingUtilities to dispatch that task back to the event dispatching thread.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i'm not sure if i got it right:
my main:

my refactored code:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using threads or there's another way?
 
Similar Threads
Generic Issue
Thread synchronisation - Using a string literal for locking
Constant running process
using threads or there's another way?
Can I Kick off Thread in JSP That Runs Even When JSP Returns?