Package examples

Class ActionExample1


public class ActionExample1 extends Application
@Action basics.

A trivial @Action example: the buttons set/clear the Frame's title:

 public class ActionExample1 extends Application { 
     @Action public void setTitle() {
         appFrame.setTitle(textField.getText());
     }
     @Action public void clearTitle() {
         appFrame.setTitle("");
     }
     // ...
 }
 
The only wrinkle worth noting is that the Action objects we've created are going to call the methods on this object. So when we lookup the ActionMap for this class, we have to pass along the ActionExample1 instance as well:
 ApplicationContext ac = ApplicationContext.getInstance();
 ActionMap actionMap = ac.getActionMap(getClass(), this);
 setTitleButton.setAction(actionMap.get("setTitle"));
 clearTitleButton.setAction(actionMap.get("clearTitle"));
 
Since our @Actions have been defined in the Application subclass itself, we can use the no-argument version of getActionMap(), which returns the ActionMap for the application:
 ApplicationContext ac = ApplicationContext.getInstance();
 ActionMap actionMap = ac.getActionMap();
 setTitleButton.setAction(actionMap.get("setTitle"));
 clearTitleButton.setAction(actionMap.get("clearTitle"));