Re: parameters for actions?

Dennis Ponos <[email protected]> 26 Jan 2005 10:19:14 -0800
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
Thanks for your explanations Frank. 


> > It appears that the specified action is always a class, not a method
> > (please correct me if I'm wrong).  If this is true, how can I specify
> 
> The "action" attribute always specifies a public field in the object
> given to the SwingEngine constructor or in the class SwingEngine is
> derived from.

Yes.  My wording was really bad.  My point was that I was expecting the
"action" attribute to be a method, not a field, of the object given to
the SwingEngine constructor.  In the examples (like the actions
example), the "action" attribute fields in Actions.java are instances of
AbstractAction that respond to the actionPerformed events. 


> 
> > what parameters this action should look for when it responds to it's
> > associated event? Does the action class need to be written in a way
> > where it is expecting to find certain values of widgets through the
> > component hierarchy?  The examples seem to perform very basic actions,
> > and don't use any parameters or components in their methods, so they are
> > not helping me very much. 
> 
> What is your goal? Write a huge actionPerformed() method switching over
> the possible parameters it received? Why not write them seperatly as 
> Actions in the first place? Or even as standalone classes using initclass?
> So you may activate them at your wish and don't need to change the 
> code checking your parameters if you do not need a certain business
> logic anymore.

No, my goal is not to write a very large actionPerformed() method.  It's
more of what you are saying, I guess my real issue is that I just don't
know how to generically get to the object values that I need in the
Action's actionPerfomed method.  Maybe the answer is simple. 

Here's an (unrealistic) example that should point out what I'm trying to
do..... 

Let's say that when a user presses a certain button, the menu items of a
certain menu should be enabled/disabled depending on the value of a
certain textfield.  I would expect to write an "action" attribute for
the button that looks like this.....

action="doMenuItemChange(menu1, txtfld1)" 

and the object that gets passed to the SwingEngine's constructor would
have a corresponding method to perform the action using the given
parameters.....

public void doMenuItemChange(JMenu aMenu, JTextfield aTextField) {
.
.	
.
}

I know that this is not how SWIXML works.  As per the Actions example,
it appears that SWIXML typically works with Actions....... 

Using Actions, I think I could get to menu1 and txtfld1 by using
SwingEngine methods like find(String).  However, my action would have to
assume that I want menu1 and txtfld1 specifically, no?  So if I wanted
to do something similar for menu2 and txtfld2, I would need to write
another Action?  If this is the case, I'm not saying that one way is
better than the other, I just want to know how it works so I can
visualize a possible design for my application.  I can easily create 2
actions that call some other class/method that performs the method
generically. 












> 
> Frank
> 
> > 
> > 
> > I don't want to get into comparing XMLGUI frameworks, but since I see
> > occasional references to Thinlet which gives me the impression that many
> > on this forum are also familiar with Thinlet, I want to use Thinlet as
> > an example.  In Thinlet, it appears that actions are tied to methods,
> > and you can specify parameters for those methods.  I guess this was more
> > of what I was expecting to see when looking at SWIXML. 
> > 
> > Any information on this subject will help me alot!  Thanks. 
> > 
> >  
> > 
> > 
> > 
> > 
> > _______________________________________________
> > Forum mailing list
> > [email protected]
> > http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com
> 
> 
> 
> 
> _______________________________________________
> Forum mailing list
> [email protected]
> http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com