aspose file tools*
The moose likes Beginning Java and the fly likes calling event from another. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calling event from another." Watch "calling event from another." New topic
Author

calling event from another.

Fernando Mendez
Greenhorn

Joined: Jun 06, 2004
Posts: 10
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

Joined: May 20, 2004
Posts: 105
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

Joined: Jun 06, 2004
Posts: 10
hi.
did u know another way to do it?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
C. Alan
Ranch Hand

Joined: Dec 17, 2004
Posts: 30
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 ]

<a href="http://www.security-forums.com/forum/viewforum.php?f=48" target="_blank" rel="nofollow">Malware Removal</a> - Get your system running like new again.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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

Joined: Dec 17, 2004
Posts: 30
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling event from another.