add(b1 = new Button("A button")); b1.addActionListener(handler); add(b2 = new Button("Another button")); b2.addActionListener(handler);