Handling Action Events

     

Examples in the Toolkit, such as the GaragePad doodler, show how to capture mouse motion events. There are also examples in the doodler application and the text editor that show how to handle action events from menu items when they're clicked.

In Swing, you create user controls for the user to interact with. When the user does something to a control ”for example, clicks a button ”that action fires an event. You create listeners that do something when that event is fired , and then attach them to the user controls. Actions can optionally hold information about tool tip text or icons, though this is rare.

Specifically, to handle an event you override the actionPerformed() method.

 

 public void actionPerformed(ActionEvent evt) {             // do something } 

There are a couple of different ways to do this. Please see the blog on Inner Classes earlier in the book for a discussion and demonstration of implementing action listeners. Please see the Toolkit in the back of this book for numerous , complete, working examples of handling action events.



Java Garage
Java Garage
ISBN: 0321246233
EAN: 2147483647
Year: 2006
Pages: 228
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net