Horus Doc || Java GUI Reference || Doxygen's quick Index  

ButtonActions Class Reference

ActionListener that maps actions to methods. More...

List of all members.

Public Methods

void actionPerformed (java.awt.event.ActionEvent ev)
void addButton (JButton button, String action)
void addButton (AbstractButton button, String action)
void addComboBox (JComboBox box, String action)
JButton makeButton (String text, String action)

Protected Methods

abstract void invoke (Method method, Object[] args) throws Exception
 The subclass has to invoke the Method. More...


Detailed Description

ActionListener that maps actions to methods.

Extend this class to add the methods associated to each button action.


Member Function Documentation

void ButtonActions::actionPerformed java.awt.event.ActionEvent    ev [inline]
 

00024 {
00025     String methodName = ev.getActionCommand();
00026 
00027     try {
00028         Method method = getClass().getMethod(methodName, new Class[0]);
00029         invoke(method, new Object[0]);
00030     }
00031     catch (InvocationTargetException ex) {
00032         ex.getTargetException().printStackTrace();
00033     }
00034     catch (Exception ex) {
00035         ex.printStackTrace();
00036     }
00037 }

void ButtonActions::addButton JButton    button,
String    action
[inline]
 

00040 {
00041     addButton((AbstractButton)button, action);
00042 }

void ButtonActions::addButton AbstractButton    button,
String    action
[inline]
 

00045 {
00046     checkAction(action);
00047     button.setActionCommand(action);
00048     button.addActionListener(this);
00049 }

void ButtonActions::addComboBox JComboBox    box,
String    action
[inline]
 

00052 {
00053     checkAction(action);
00054     box.setActionCommand(action);
00055     box.addActionListener(this);
00056 }

JButton ButtonActions::makeButton String    text,
String    action
[inline]
 

00059 {
00060     JButton b = new JButton(text);
00061     addButton(b, action);
00062     return b;
00063 }

abstract void ButtonActions::invoke Method    method,
Object    args[]
[protected, pure virtual]
 

The subclass has to invoke the Method.

ButtonActions can not invoke the method if the subclass is a private inner class. The subclass just have to call method.invoke(this, args).


The documentation for this class was generated from the following file:
Generated on Mon Jan 27 15:11:13 2003 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001