Learn to create multiple frames in java

0
1260
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

img 1

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

img 2

img 3

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

img 4

    1. Follow the below steps to create new class :

 

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

img 5

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

img 6

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

img 7

Example :

OldWindow.java

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 :

NewWindow.java

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

Output :

Output 1

You will get below output :

Output 2

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here