tags:

views:

43

answers:

3

For the life of me I cannot seem to find details on Java Swing Actions :'( When I came across them I immediately realised their usefulness. So far it's all been easy to work with. Now I'm stuck with one little thing: How do I run them manually? I mean by code? Note that I am building the GUI using Netbeans (if that makes any difference). I've come as far as:

Application a = Application.getInstance(JPADemoApp.class);
ApplicationContext ctx = a.getContext();
ActionMap am = ctx.getActionMap(JPADemoView.class, this.app);
Action act = am.get("fetchOrders");

( I wrote all on separate lines to simplify debugging )

So now I have a valid reference to the Action. Now how do I run it?

+1  A: 

Have a look at the Sun Tutorial: How to use Actions.

aioobe
+2  A: 

If you want to run your action manually, you can generate an ActionEvent and pass it into the actionPerformed method that your Action must implement, as the Action interface extends ActionListener.

akf
+1  A: 

Because an Action is an EventListener, you may want to consider implementing an EventListenerList as a way to expose methods that fire actions.

trashgod