Learn to create multiple frames in java


In this tutorial we will learn to create multiple frames in java. Here we will be creating two classes for example OldWindow and NewWindow class respectively. OldWindow class will consist the actual logic for frame creation while the NewWindow class will have the design structure of JFrame .

  • So, to learn to create multiple frames in java follow the steps given below :


    1. First of all open up eclipse -> Go to File-> New-> Java Project, just select the Java Project as shown below :


    1. After selecting Java Projet a dialog box will pop up asking for project details. So, fill the respective details and click on Finish button.

    1. Now, you can view your project and select it from the package explorer present at the left hand side.

    1. Now let’s create two new java classes called as OldWindow and NewWindow respectively. So, for generating these class, select your project -> right click on src -> New -> Class as shown below :

    1. Now insert the respective class details :

    1. Similarly, create NewWindow class and now you will be having your both the classes generated in your project in the package explorer.

class created

    1. Now open up OldWindow.java class and write the actual logic code, which will create JFrame, JButton and open up a New Frame to display.


    1. Insert the given code in OldWindow.java class:



    1. Just follow the comments to understand the code.


    1. Now, open your NewWindow.java class and add the given code which creates JFrame, JLabel into the New Frame.



    1. We are all done. Now, just select your project from the package explorer and run it.


    1. You will have the following output:

    1. After clicking the new button you will be navigated to new window as shown below:

Thus, we have successfully learnt to create multiple frames in java and navigated from one frame to another.


  1. Thanks for your post, Could you please tell how to get back to old window by clicking a button in the new window? thank you very much. I am desperate for this answer.

  2. JFrame is a window commonly used for stand-alone applications, like a warning window, or a notification window . Thanks for sharing this blog , keep blogging.


Please enter your comment!
Please enter your name here