I've got a problem: I've got a jframe1 who calls at ActionPerformed the jframe2. JFrames are threads or? and so I've tried in the jframe2 the wait() method, and then I would notify the jframe2's in jframe1..
my code in jframe2 (a method what run, when a button is clicked):
private void read(){
synchronized(jframe1){
try {
if(writer.checkLast() == null){
this.wait();
jLabel.setText(writer.getLast());
}
else{
jLabel.setText(writer.getLast());
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
But the Problem is, that if I use this.wait(); in jframe2, my jframe1 is also locked.. what I do wrong?
sry for my bad english, thanks if anyone have got an answer!
No, absolutely not. There is one single thread in which all painting and user input events happen, the Event Dispatch Thread. However, this thread is different from the application's main thread, which is probably what lead you to believe that each frame has its own thread.
Since all events happen on the event dispatch thread, you don't have to do any synchronization, and your frames can call each other's methods without requiring any synchronization or notification. Which is the reason for the single threaded design in the first place (The general consensus is that a multithreaded GUI is nearly impossible to work with).