Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes using threads in swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "using threads in swing " Watch "using threads in swing " New topic
Author

using threads in swing

Suman Mummaneni
Ranch Hand

Joined: Dec 14, 2004
Posts: 87
Hi I am a swing programmer. I want to know if I can use threads in my swing application that I am developing. I also want to know if I can make some classes abstract/intreface so that in future i could use them while programming.

Cheers!
Suman


Suman Mummaneni
Bangalore
India
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8713
    
    6

The Java Tutorial: Building a GUI with Swing: How to use Threads should answer your first question.
As for your second question:

I also want to know if I can make some classes abstract/intreface so that in future i could use them while programming.

What makes you think that you couldn't?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Dave Mace
Greenhorn

Joined: Jan 04, 2005
Posts: 11
Yes, you can definitely use threads. In fact, anything that is going to take some time to process (i.e. database reads, i/o activity, etc) you should consider moving the processing of those tasks to another thread.

The problem if you don't is that they block your Swing Event Thread from processing any GUI activity which results in a perceived application lockup to the end-user because the GUI will not respond until the offending method call finishes and unblocks the EVT (event thread).

Make sense?


Dad always thought laughter was the best medicine, which I guess is why several of us died of tuberculosis. -Jack Handy
Jason Kingsley
Greenhorn

Joined: Feb 21, 2004
Posts: 18
The essential thing to remember with threads is the magic paradigm - "never update a control on a thread other than the event thread". This means that you have to manage access to controls from any worker thread.

Take a look at http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html for some useful information and pay attention to the utility class SwingWorker. This class makes life a little easier for managing calls across threads to the event thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using threads in swing
 
Similar Threads
How swing follows MVC pattern
Look and Feel
Need Info can use swing and ejb
Need info about Swing and EJB
Need Info. JSwing and EJB