aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes controlling user actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "controlling user actions" Watch "controlling user actions" New topic
Author

controlling user actions

Varaku Venkata
Ranch Hand

Joined: Mar 17, 2002
Posts: 30
Hi
I am using a controller class for managing the user actions in gui. In this controller class i am planning to catch the user actions and pass accordingly to ClientHelper class which will process the values and return back to gui.
In this situation, I am having problem with catching the distinct user actions. I am having three combo boxes for selecting a search criteria. now i want to listen to these comboxes seperately in a new class called controller class.
Though with getSource() or getActionCommand() i am able to listen to any particular combobox , i want to listen to each of them seperately...like if he selects origin i want to know that he has selected origin combobbox, and if he selects carrier , then i want to know that user has selected carrier combobox....Are there any methods for knowing these details ???
Thanks
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
How about in your controller class, add 3 inner class listeners for each of your JComboBoxes?
Varaku Venkata
Ranch Hand

Joined: Mar 17, 2002
Posts: 30
Hi sai,
I can do that ... and will get back to u if i face any problems...
thanks for the reply...
venkat
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Varaku
I feel as though you want to know what values the user has selected.
I think the time when you really want to know these values is when the user clicks the search button.
So you can use the code that Sai is talking about to catch the Action when the user clicks the search button, and then get the values from the JCombobox directly from the GUI.
Your controller has a reference to your GUI, so you should be able to get those values.
Hope that helps
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Varaku Venkata
Ranch Hand

Joined: Mar 17, 2002
Posts: 30
Hi Mark,
I can tackle the issue of catching user actions by using seperate listener classes for each GUI item in the controller class. but what i actually wanted is , i wanted to keep only one listener class in controller class which takes care of all the user actions in gui class. i.e i want to make controller listener class as generic as possible.. this listener class will listen to all the events in ClientGUI class and basing on which GUI item has called it , i want to do some actions for it.
For Eg; if user clicks on origin combobox and selects some origin ...i want to know from the listener class that user has selected some value in origin combo box.
similarly,if user clicks on carrier combobox and selects some carrier ...i want to know from the same listener class that user has selected some value in carrier combo box .
this can only be achieved by gettting the correct source which has generated the event. so, my question is how to get the correct source ( out of so many sources which generates so many event ) in only one listener class.
using getSource() of ActionListener class we can know that a comboxbox has generated that particular event...but i want to know out of three combo boxes which combox has generated the event....

venkat
[ May 28, 2002: Message edited by: Varaku Venkata ]
[ May 28, 2002: Message edited by: Varaku Venkata ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

For Eg; if user clicks on origin combobox and selects some origin ...i want to know from the listener class that user has selected some value in origin combo box.

Ok, so then why do you need this information.
getSource will give you the object that caused the action to occur.
I would highly recommend you not have one single "Action Catcher" then determine the source and shell out accordingly. That means lots of if statements in that one ActionPerformed, which is hard to read to other programmers.
If you have seperate hooks for each item that you really need information from, you code will be cleaner, easier to read, which means more maintainable.
Mark
Varaku Venkata
Ranch Hand

Joined: Mar 17, 2002
Posts: 30
Hi Mark,
As I have said , using getSource() i am unable to distinguish one combobox from another. so i wanted a way to distinguish each combobox...
anyway as u said i will try using different listener classes for each GUI item .
Thanks for your replies...
 
 
subject: controlling user actions