Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

2 Swing JFrames concurrently are blocking  RSS feed

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi :

Im trying to execute 2 swing jframes at once...

frame1.run();
frame2.run();

while(a.getState() != a.FINISHED)
{
ard.update(System.currentTimeMillis()+"");
}

That is, the first frame is a UI , the second is a timer running
in the background.

The problem Im having is that frame2 always blocks frame 1.

Any suggestions
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFrame does not have a run() method so what exactly are you calling and how? All GUI will take place on the EDT and if you block that then you'll block all GUI.
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frame1 and Frame2 are both classes that create JFrames.
So I guess you cant create a JFrame inside of a "run" method in
a threaded class and expect it to have threaded behavior ?
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on what you mean by "threaded behavior". No matter where you create the JFrame the painting and events won't be executed on a different thread. There is exactly one thread where all painting, events, updates, etc. occur and that is the EDT (event-dispatching thread). Read more about it here:

http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay - so basically my problem was I was getting an Illegal Monitor excpetion,
and I fixed it by adding "synchronized" to the method name of the object... thanks !
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!