Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling event from another.

 
Fernando Mendez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.

i want to know how to call an event from another event, like a mouse_click event from keypress event.

THANX.
 
Shashank Agarwal
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure how to do that but theres another way to go about it. (see code)



This way you can get what you want to be performed when mouse is clicked as well as when the key is pressed.

Hope that helps. I'd prefer a better solution myself.
 
Fernando Mendez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.
did u know another way to do it?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was actually a pretty good design direction: get the code out of the event handlers into nicely named methods that tell you what they do in response to the event. One event simulating another just doesn't sit well with me as a design. Two widgets - a button and a menu - doing the same thing sounds much better.
 
C. Alan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I can help out on this one..if I am wrong, someone will tell me, and then we both learn.If I am understanding you correctly, you are trying to assign multiple events to a single action?

I usually don't get to offer help, but here goes...



What I have here is an actione being created, and a Jbutton associated with it, as well as a mnemonic key. By either clicking on the button, or pressing ALT-c, I trigger the event. I would guess that you could add the same event to other actions also.
[ February 08, 2005: Message edited by: C. Alan ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did that compile and do what you wanted? Of course you can tell I'm guessing "no" but give it a try and see what it does!
 
C. Alan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code? No, that won't compile all by itself. It needs other things, you know, like a main method, constructor, etc. However, inside my class, it works perfectly.

Should I have presented it as a complete method?
[ February 09, 2005: Message edited by: C. Alan ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fernando mendez:
hi.
did u know another way to do it?


There are always more than one way to solve a problem, especially when it comes to computer programming. I believe the above suggestions are all bassed on pretty good design principles. If you don't like these ideas, what suggestions do you have for doing it differently?

Layne
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the taunting tone of that last post ... I wasn't familiar enough with Action to grok all of what you were doing. But at the top it seems to give the button a null action.

Your example fits nicely with what I suggested earlier so long as your "code to be executed goes here" is a one-liner calling a meaninful method. Maybe on a controller if you're into MVC.

I don't do much Swing, but I made some stuff like this:

(Sorry about the "m" prefix on "member" variables. I got over that habit later.)
[ February 10, 2005: Message edited by: Stan James ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic