Action listeners are put in a list and, I assume, are called based on their order in the list.
Can you put them in the list (ie add them) in the order you want them called?
Does the component have methods for getting to the list of listeners that would allow you to change their order?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
how do I add the ActionListeners of the component to the execution list BEFORE I add the ActionListeners of my objects?
The same way do you do anything in a program. You execute the statements in order that you want them executed.
I'm not understanding your problem. If you want A done before B, the do A first and then do B.
Is there one object with a number of actionListeners?
When the object has an action, does it call the listeners that have been added to it in the same order as they were added?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
What is the purpose of the new action listeners you are adding to the component? Are they to track when the value of the field is being changed by the buttons?
If so, wouldn't it be better to implement an addChangeListener method for the whole component that will register listeners and call them back passing a ChangeEvent after updating the text field?
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
I would rather get the ActionListener(s) to fire in the desired order.
(The ActionListener in the component FIRST, THEN the ActionListener in MY program SECOND.)
Can you add the component's AL first and the MY program's AL second?
Did you look at the methods for adding, gettting and removing action listeners?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
That's what I suspected. Just take a pace backwards and look at this from a higher level. You don't want to know about the individual buttons firing - that's just part of the internal implementation of your new component. You want to know when the value of the variable in the component has changed, and don't care if that was from a button, an up or down arrow key, mouse wheel scroll, or any other user interface you may implement now or later. You just want a ChangeListener on the component.
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
that reason why javax.swing.Action exists, then you can forgot for override KeyBindings, PropertyChangeListener and MouseListener,
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
You would need to add that method to your class if your class does NOT extend a class that has it. Look in the API doc for a long list of classes that have that method.
You would also need the remove method and an internal list to save listeners in and a method to call the listeners when there is an event.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Yes, Norm's right. It's about a dozen lines of code in total; nothing difficult. Depending on you application you may not need the remove method, and you may be able to work with just a single listener instead of a list - that will almost halve the code, and you can always upgrade them later without changing any public method signatures.
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Or... if your class doesn't extend anything yet you can simply extend Observable and inherit all the methods you need.
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
OP's probably coding for Alliens, and in connections with these fact he's prohibited to sent here more infos, all of us have got false impression, maybe then there is for OP's more than fun :-)
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
OK hfx.. I've just been made "member of the month", so I'm in a really really good mood. Here's some code as a free gift from me (non-commercial use only).
// ChangeListener implementation
ArrayList<ChangeListener> listeners = new ArrayList<>();
public void addChangeListener(ChangeListener listener) {
listeners.add(listener);
}
public void removeChangeListener(ChangeListener listener) {
listeners.remove(listener);
}
void notifyListeners() {
// call this whenever data is changed
ListIterator<ChangeListener> iterator = listeners.listIterator();
while (iterator.hasNext()) {
iterator.next().stateChanged(new ChangeEvent(this));
}
}
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
ComponentListener + Model + javax.swing.Action
some listeners allows Listener#Method#putProperty(String, String)
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
That's a shame! I always hate to see programs kludged like that. Never mind, it's your project, not mine. If you change your mind let me know and I'll walk you thru the tiny amount of code needed to do this "properly". Good luck. J
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073