Common question asked by java Swing/AWT/SWT Windows builder UI developers, how to link one frame to another in Java swings. There are plenty of ways to link one Frame to another frame, i will discuss all the different ways to do this process.
Lets Assume 2 Frames TestFrame1 and TestFrame2 , on the action performed of TestFrame1 we must open the TestFrame2.
How to open Another Frame on Button Click
Assuming the 2 frame as per the examples. The first frame must have a JButton with action performed event. see the below code and try
TestFrame2 tf2 =new TestFrame2(); tf2.setVisible(true);
if you want to close the TestFrame1 on opening TestFrame2, you can write dispose method after setVisible(true)
how to write the same code in single line.