+ 1

What should I do with jButtonActionPerformed() ,si that when button is clicked then it will open a new window(new frame)?

Please help me via giving some lines of code

13th Sep 2017, 4:46 AM
Hemant Jaiswal
Hemant Jaiswal - avatar
2 Respostas
+ 5
public class Main extends JFrame implements ActionListener{ public Main(){ JPanel panel = new JPanel(); JButton testbutton = new JButton("Click Me"); panel.add(testbutton); testbutton.setBounds(5,5,80,30); testbutton.addActionListener(this); public void actionPerformed(ActionEvent e){ Object source = e.getSource(); if(source==testbutton){ JFrame frame2 = new JFrame(); } } } public static void main(String[] args){ JFrame frame = new Main(); frame.setSize(300,300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setVisible(true); } } There can be errors here since I dont have my laptop right now. It's up to you to find those. I hope it helps 😉
13th Sep 2017, 7:37 AM
Joe McMillan
Joe McMillan - avatar
+ 2
Thanks Joe
13th Sep 2017, 7:58 AM
Hemant Jaiswal
Hemant Jaiswal - avatar