I made a program, it displays a window with 4 buttons. How to make it so that after clicking on any of them, another window is displayed ( JFrame )? Here is the code:

 public class InterfaceCalq extends JFrame { JButton button0 = new JButton("1"); JButton button1 = new JButton("2"); JButton button2 = new JButton("3"); JButton button3 = new JButton("4"); JPanel panel = new JPanel(); public InterfaceCalq() { super("Калькулятор по-формулам"); this.setBounds(100, 100, 100, 100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new FlowLayout()); panel.add(button0); panel.add(button1); panel.add(button2); panel.add(button3); this.add(panel); } /** * @param args the command line arguments */ public static void main(String[] args) { InterfaceCalq inter = new InterfaceCalq(); inter.setVisible(true); } } 

    1 answer 1

     button0.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFrame frame = new JFrame(); frame.setSize(100,100); frame.setVisible(true); } });