wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes do something when other frame close Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "do something when other frame close" Watch "do something when other frame close" New topic

do something when other frame close

Edward Fernando

Joined: Feb 14, 2012
Posts: 4
hello, i need help in java about swing...

i have 2 class which have frame in it, let say classA and classB
is there any way so that when frame in classB closed i do something in classA
for example when classB closed a textArea in classA will write a text.

i've done this in classA

but there is nothing happen....please help me...
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38016
Welcome to the Ranch

Why have you got two frames? Why not use a dialog for the second window?
You can add a WindowListener which fires when a frame closes.
[edit]I see you already have such a listener[/edit]
Darryl Burke

Joined: May 03, 2008
Posts: 4523

but there is nothing happen....please help me...

Impossible to help without seeing all the relevant code. To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

And I second Campbell's advice: most applications are best designed with only one JFrame, and other UIs as JDialogs, commonly modal.

edit Your initComponents() call implies that you are using a visual designer -- definitely not a beginners' tool. Is that guess correct?

luck, db
There are no new questions, but there may be new answers.
Consider Paul's rocket mass heater.
subject: do something when other frame close
Similar Threads
Q about UML Distilled: transient relationship?
Need Help! How can I......
Thread - Wait() and Notify();
Scope and classes/methods
Java Compiler