Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is it a single thread or multiple thread for different jframe

 
sneha kk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a JFrame (A) within main method and if I create another JFrame or JDialog (B) from an action event from a component wihin JFrame (A), then are A and B going to be two separate threads or are they running under the same thread.

Can anyone point me to any link or explain this kind of scenario...

Thanks.
 
Stephan van Hulst
Bartender
Pie
Posts: 5373
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should all run under one thread, the Event Dispatch Thread. Essentially what happens is when you hit a button or some other action or event or whatever happens in Swing, it gets added to a queue of events which Swing needs to handle. The Event Dispatch Thread takes one of these events out of the queue at a time, and dispatches it, in other words, it performs the tasks associated with that event.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All Swing components should be working on the same thread, the EDT, all listeners call their methods on the EDT. You will have to take care however if you do any background thread work in your app, and be sure that you abide by this rule when calling Swing methods or creating Swing components.
 
Campbell Ritchie
Sheriff
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you open any Swing component's API it says
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Read the link they provide.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic