Blackvein
Blackvein

Reputation: 558

Java: Dispose ActionEvent from different JFrame

I want one JFrame to have a method like this:

private void someEvent(java.awt.event.ActionEvent evt){

    //initialize another JFrame
    //set the new JFrame to be visible
    //set this JFrame to be disabled

}

Which is possible, but I also want the main JFrame to perform something when the newly created JFrame is disposed. I don't want to pass in the main JFrame to the new JFrame however. Is this possible?

Upvotes: 3

Views: 262

Answers (2)

trashgod
trashgod

Reputation: 205775

Instead, use CardLayout to switch between the two desired content panes. There's an example here.

Upvotes: 4

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

Don't have one JFrame create and display another JFrame. Instead the second window should be a JDialog, either modal if you want the first window frozen until the second has been dealt with or non-modal if otherwise. If modal then the first window's code will resume once the JDialog has been disposed of, and the code flow will start right after the setVisible(true) call on the dialog. If non-Modal, you'll likely want to add a WindowListener to the dialog.

For example, please check out my code here, here, and here.

Upvotes: 4

Related Questions