开发者

problem while linking new.java to home.java

开发者 https://www.devze.com 2023-03-14 03:35 出处:网络
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 o

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消