Create button to implement windowClosed event
I am wondering if it is possible to create a button on a forum that would act the same as the X button in the window.
or if there is another way that i can let my parent frame, that created this new frame, know that the child frame has been closed so that the parent frame can carry on as normal until the next child frame is created.
[347 byte] By [
ChisMa] at [2007-10-3 8:19:38]

Yes, add an action to the button or an action listener. Then close the frame.
> Yes, add an action to the button or an action
> listener. Then close the frame.
i'm sorry, but i need you to be a little more specific.
i have added an actionlistener to the button, but i'm unsure how to close the windows exactly.
i have tried this.dispose, and this.setVisible(true), but neither or those work the same as using the X button.
also i'm using to detect when the child window is closed
mainFrame.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(WindowEvent winEvt) {
do something;
}
});
I think a better design would be to put the do something code in separate method and have the action listener and the window listener code both call it.(This is just a suggestion because I haven't seen all of your code)
> I think a better design would be to put the do something code in > separate method and have the action listener and the window listener code both call it.Something like this: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=695964
ok, i don't think i made my issue clear, but i might be designing this a poor way so let me know.
my parent frame creates another frame, and listens for it to close
JFrame edit;
if ( frame not open ) {
edit = new Edit_Applicator("Edit Applicator",380, 500, true);
edit.setAlwaysOnTop(true);
edit.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(WindowEvent winEvt) {
do thing;
}
});
}
then when i close the child i want it to be able to tell the parent that it has closed. if they click on the X my current method works perfect. however, i want to create an exit button on the child frame that will let the parent frame know it has closed as well.
i have created the button and the actionlistener for the button, but i'm not sure how to get the button to close the same way that the X button closes the frame, and have the windowlistener in the parent "hear" that the child closed.
the button that i'm refering to is in my child frame, and window listener is in my parent frame. i'm not sure how your reply helps me.
> the button that i'm refering to is in my child frame,
> and window listener is in my parent frame. i'm not
> sure how your reply helps me.
Did you follow his link?
Have the child action listener call the same method that the parent frame window listener would call.
Make it a public method somewhere and put the "do something" in that method.
Frame f = new Frame();in the action listener for the button do thisf.postWindowEvent(WindowEvent.WINDOW_CLOSING);
that method has package level access so you would need to call it from a subclass of frame.
ok ok, i get what you saying now. sorry, it's been a while since i've done java work. thanks for your patience.is there a way that i can call the "parent class" method other than just making an object of the parent in the "child class"?
> is there a way that i can call the "parent class"
> method other than just making an object of the parent
> in the "child class"?
foolish me, making a new object of the parent class won't work as it is a new object.
how can i call a method from the class that created my new frame object?
> how can i call a method from the class that created> my new frame object?You need a reference to it. You can pass it to your object when it is created.
> You need a reference to it. You can pass it to your> object when it is created.thanks a lot zadok. that works perfectly now.
ChisMa at 2007-7-21 12:24:32 >
