![]() |
event handeling assistance
I have a menu bar with some menus, file->open, new, save..etc. But I also have a tool bar that I placed buttons on for open, new, save..etc.
My problem is I'm not sure how to have these buttons fire the same events as those from the menu bar. I know I can do getActionCommand() and see if it equals the string name of the button, but I have the buttons set as images so I never assigned a string name to them... is there a way I could over ride getActionCommand() to say check for the name of the button as opposed to the string so I can throw an 'or' and see if it was either triggered from the file menu OR the button I have specified located on the tool bar. :
I originally thought I had gotten around this problem because I added anonymous listeners, however, with my "open" event I use a JFileChooser and for some reason if I make an anonymous listener with any code pertaining to a JFileChooser the compiler yells.. :
jbtOpen.addActionListener(new ActionListener(){I hope my problem has been made clear. Thanks a ton to whoever helps me out. Very much appreciated. |
This may help.
http://java.sun.com/docs/books/tutor...ents/menu.html |
Good call. I figured it out.
I moved the code with JFileChooser into a function, then whenever the button was selected, I just added an anonymous listener that called the function, it got me around the "you can't have a JFileChooser here" error. Thanks a lot mrynit. |
I'm in java GUI now and we did that example as part of our lab. If you need more GUI help I can provide some data.
|
| All times are GMT -5. The time now is 2:06 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC