I have two files: home.java
and ne开发者_StackOverflow中文版w. java
When I click a button in home.java
called "new", new.java
should open and it is opening correctly if I am including these lines of code in actionPerformed
method of button:
home newinstance = new home()
newinstance.setVisible(true);
Everything is going according to the plan except that the new.java
is opening in new window and the old home.java
is not dissapearing
I want the new.java
to come not as new window but same window and home.java
to disappear. (If first will occur second wil automatically occur)
Instead of both being windows (JFrame) let both be components (extend JComponent) which you put inside a single window.
frame.getContentPane().add(new Home());
frame.setVisible(true);
void actionPerformed() {
frame.getContentPane().removeAll();
frame.getContentPane().add(new New());
}
I'm assuming you use Swing. If you're using AWT, well...use Swing :p
(Also, classes in Java should be Capitalized, and it's a bit confusing if you refer to them as .java)
精彩评论