-1

I wanted your help with coding to change from one frame to another in netbeans. But I also want to make the first page disappear and only keep the second form visible. I have managed to do this for 2 forms but it doesn't work when I use this code to go from first to second and then from second to third frame.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    Don't use multiple frames. Instead you can use a [Card Layout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html). – camickr Jun 09 '17 at 19:47
  • 1
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jun 10 '17 at 01:12

1 Answers1

0

What you need is dispose() When you open make the instance of your new window and make it visible the last window should be taken down.

The dispose method destroys the window called on, so be careful with it cause if there's not another window available it will make something similar to System.exit(0);

Jesus Walker
  • 116
  • 10
  • nope.Having the same problem again.I am able to use it for 2 frames but it doesn't work when using for 3 or more(in my case 5). Is it possible to combine all of my frames to one class ,and if yes will it work.Thanks! – shubham varade Jun 10 '17 at 18:27
  • *"Is it possible to combine all of my frames to one class"* If by that, you mean is it possible to combine the GUI controls all into one frame, then you obviously have not followed the link to the question I put in yesterday's comment. – Andrew Thompson Jun 11 '17 at 16:54