answersLogoWhite

0

There are many ways to accomplish this but one way I might accomplish this is with a WindowListener or WindowAdapter. Below is a skeleton structure:

package pkg;


public class ExampleMainFrame extends JDialog

{

public ExampleMainFrame(final Window parent)

{

super(parent);

// ... Do other stuff for initialization here or in another internal method


addWindowListener(new WindowAdapter()

{

public void WindowClosed(WindowEvent e)

{

(new ExampleDialog2(parent)).setVisible(true);

}

}

}


// ... Other methods

}


(In different .java source file)

package pkg


public class ExampleDialog2 extends JDialog

{

public class ExampleDialog2(final Window parent)

{

super(parent);


// ... Do other stuff for initialization here or in another internal method

}


// ... Other methods

}



Explanation:

WindowListener is an Interface - WindowAdapter is a class that defines empty method definitions for each of the methods so you can effectively define/override one of the methods and instantiate a WindowAdapter and it won't do anything but what you've overridden. In this example, I've overridden WindowClosed and upon that event occuring, it'll create and show the 2nd frame.

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor

Add your answer:

Earn +20 pts
Q: How do you close a frame when opening another frame in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp