Thanks a log!

It seems that its the style of java programming to instantiate new
classes all the time. In this case, the normal way seems to be to
declare a new class for every menu item and to instantiate each of
these classes a single time, just to connect a menu item to a piece of
code. Ist this the normal way in java? Doesn't this blow up the code
in an unnecessary way??

Magnus

On May 29, 8:25 pm, kozura <[email protected]> wrote:
> No, but you can do something close:
>
> m.addItem("Login", new MenuCmd(1));
> m.addItem("Logout", new MenuCmd(2));
>
> class MenuCmd implements Cmd
> {
>     private int whichCmd;
>     public MenuCmd(int which) {whichCmd = which;}
>     public execute()
>     {
>         switch(whichCmd)...
>     }
>
> }
>
> On May 29, 8:08 am, Magnus <[email protected]> wrote:
>
> > Hi,
>
> > I would like to give all my menu items the same command object:
>
> >   m.addItem ("Login", cmd);
> >   m.addItem ("Logout", cmd);
> >   m.addItem ("Register",cmd);
> >  ...
>
> > Is it possible to retrieve the selected menu item within the command
> > object's method "execute"?
>
> > The reason is that I want to keep my code compact, i. e. using a
> > single method that reacts on menu item selections and distinguishes
> > the items with a select statement...
>
> > Many thanks
> > Magnus

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to