This content has been marked as final. Show 10 replies
Yes, you are correct. But my main problem is that "MyObject" do not contain the method addActionListener(Object o). Do I need to write addActionListener(Object o) in "MyClass" somehow?
Edit: box1 and box2 are start and end values. That mean they need to check each other when one of them are changed. Thats why I would like to have an actionListener(this) that runs for both my boxes in MyClass
Edited by: Hunter_wow on 2013-jan-09 01:06
Hunter_wow wrote:EDIT: indeed, input components have an addActionListener(), not JPanel. I'm so rusty that I just completely missed that. You can still make a JPanel clickable by using mouse listeners in stead of an action listener, should you in the future be looking for something like that.
Guess the correct answer is to do something like this:
Thanks for making me think =)
Best source of guidance are the Javadocs by the way.
Those are a whole bunch of inherited methods, but you can simply do a search in the browser for the method you're looking for to know the truth (it ain't there).
Events listeners are added on the source component and they eventually generates events on some user action.
In your case the combo boxes works as source ..so you can add the same action listener on both the combo boxes ,and in the action performed method
you can check that from which source (combo box 1 or combo box2 ) the event is generated and take the action accordingly.
public void actionPerformed(ActionEvent ae)
You can use anonymous inner class instead of writing a new class. For this, you need not implement the ActionListener interface.
Here MyClass need to implement the ActionListener interface and then write addActionListener(ActionListener) in the MyClass (according to you)