import java.awt.*; import java.awt.event.*; import javax.swing.*; class GUI extends JFrame implements ActionListener { public static void main(String[] args) { GUI window = new GUI("Title"); //window.setLayout(new FlowLayout()); } private JButton button; private JButton button2; private JButton button3; //Inner class private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent a) { System.out.println("Hello from the Inner Class"); } } public GUI(String title) { super(title); JPanel panel = new JPanel(); setSize(400,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(panel, BorderLayout.SOUTH); button = new JButton("Click me!"); button2 = new JButton("Also click me!"); button3 = new JButton("Annother Button"); button.addActionListener(this); button2.addActionListener(new ButtonListener() ); //Anonymous Inner class button3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("Clicked button 3"); } }); panel.add(button); panel.add(button2); panel.add(button3); setVisible(true); } public void actionPerformed(ActionEvent ae) { if(ae.getSource() == button) { System.out.println("Hello world"); } else if(ae.getSource() == button2) { System.out.println("Different output"); } } }