answersLogoWhite

0


Best Answer

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

11y ago
This answer is:
User Avatar

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
Related questions

How can you run frame program in java?

Same as that of the applet we need to run this frame...........


What is the main difference between java and dotnet?

java is from sun and .net is from microsoft, java is a language + runtime and .net is run frame that supports multiple language.


What is Java Swing Frame?

A top-level window (i.e., a window that is not contained inside another window) is called a frame in Java. The AWT library has a class, called Frame, for this top level. The Swing version of this class is called JFrame and extends the Frame class. The JFrame is one of the few Swing components that is not painted on a canvas. Thus, the decorations (buttons, title bar, icons, and so on) are drawn by the user's windowing system, not by Swing


What is java frame?

It is basically a windows, that contains other visual objects.


How do you run the frames in java?

first compile java program using "javac" then run frame using "appletviewer". e.x. = appletviewer filename.java


What is Jivanese?

There is no widely recognized term or concept known as "Jivanese." It may be a misspelling or a reference to something not commonly known. If you can provide more context or details, I might be able to offer a more specific answer.


What do you mean by Frame Work in java?

A set of classes that helps you with some particular task.


Why coffee cup is used as a java symbol?

Java is another way of saying coffee


How do you make the result of pressing a button appear in another box in java script?

What do you mean by "another box"? Another window? Another frame? Another text box element? All of these things are addressable in the browser's DOM, but how you address them depends on what you mean by "another box", so provide some more detail and we'll see how we can help.


How nesting of methods is done in java?

No, Java only allows a method to be defined within a class, not within another method.


What is the full form for java?

JAVA is the name of a programming language as such and there is stands for Just Another Vague Acronym.


What is meant by function header in java?

That means, the header of a function. The header is the top part, before the opening braces.