• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

using threads in swing

 
Ranch Hand
Posts: 99
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
A wop bop a lu bop a womp bam boom! Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic