Open Second Frame With Button in Java

Open Second Frame With Button in Java:

https://youtu.be/2NQGemFB_jQ ________________________________________________ How to make Button for open Second Frame in Java?

package Test;


import java.awt.event.*;

import javax.swing.*;

public class OpenSecondFrameWithButton

{

public static void main(String[] args)

{

JFrame frame1 = new JFrame("First Frame");

frame1.setBounds(500,100,500,300);

frame1.setLayout(null);

frame1.setVisible(true);

JButton btn1 = new JButton("Open Second Frame");

btn1.setBounds(140,200,200,20);

JLabel lbl1 = new JLabel("First Frame");

lbl1.setBounds(100,100,200,20);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JFrame frame2 = new JFrame("Second Frame");

frame2.setBounds(700,100,500,300);

frame2.setLayout(null);

frame2.setVisible(true);

JLabel lbl2 = new JLabel("Second Frame");

lbl2.setBounds(100,100,200,20);

frame2.add(lbl2);

}

});

frame1.add(btn1);

frame1.add(lbl1);

}

}

________________________________________________

Dark Hers

https://darkhers.blogspot.com

YouTube

https://youtube.com/@darkhers

Instagram

https://instagram.com/darkhers

Facebook

https://www.facebook.com/darkhers

TikTok

https://www.tiktok.com/@darkhers

Pinterest

https://www.pinterest.co.uk/darkhers

Twitter

https://twitter.com/Dark_Hers

Comments

Popular Posts