Skip to content
Advertisement

Opening a new window on a button click in java

I’m just starting with using interfaces in java, I’m okay with having just one window and that doing what i need. But i now want to link two windows together e.g.

Frame 1 opens. user chooses button1 (enter data). Frame 2 opens so user can enter the data.

Code for Frame 1:

JavaScript

Code for Frame 2:

JavaScript

Basically I would like some help with linking these two programs together so that the user can open the first frame choose which action they would like to do.

I have only been working with the console up until very recently so if my code is not perfect I apologise but I would really appreciate any help with this.

I would eventually like to get this program https://repl.it/repls/FondAptXeme to have a GUI if this helps at all.

Thanks

Advertisement

Answer

I would suggest creating a new JFrame and setting the visibility of your new JFrame to “true” in the button’s action listener. Something like this:

JavaScript

and then in your button1 action listener you do:

JavaScript

EDIT:

JavaScript

Cheers.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement