Handling Events with an Anonymous Class If an event handler is specific to a component (that is, not shared by other components), there is no need to declare a class to handle the event. The event handler can be implemented using an anonymous inner class. This example demonstrates an anonymous inner class to handle key events for a component. component .addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { } }); Handling Action Events Action events are fired by subclasses of AbstractButton and includes buttons, checkboxes, and menus. AbstractButton button = new JButton(quot;OK"); button.addActionListener(new MyActionListener()); public class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent evt) { // Determine which abstract // button fired the event. AbstractButton button = (AbstractButton)evt.getSource();
About Java and it's related concepts..