Learn to create multiple frames in java

featured image

This tutorial provides brief explanation about creating multiple frames in java where we will be creating two classes i.e. OldWindow class and NewWindow class. OldWindow class will deal with the actual logic of frame creation and NewWindow class consists the design structure of JFrame.

    1. Open Eclipse, Go to File-> New-> Java Project, you will get below view

    1. A dialog box will pop up which will ask you to enter the project details.

    1. Select your project, from the package explorer as shown below :

    1. Follow the below steps to create new class :


      1. Click on Project, right click on src -> New -> Class as shown below :

      1. A dialog box will appear where you will have to set your class name and then select Finish button.

      1. Now create two classes one is OldWindow.java and second one is NewWindow.java .

Example :


In this OldWindow.java write the actual logic code, in this class write the code which creates JFrame, add JButton for open New Frame.

Example :


In this class write the code which creates JFrame, add JLabel into the New Frame.

Output :

You will get below output :

Simillarly, you can create multiple frames and navigate from one frame to another.

Thus, in this tutorial we successfully learnt how to create multiple frames in java.


Please enter your comment!
Please enter your name here