public class AWTEventMulticaster extends Object implements ComponentListener, ContainerListener, FocusListener, KeyListener, MouseListener, MouseMotionListener, WindowListener, WindowFocusListener, WindowStateListener, ActionListener, ItemListener, AdjustmentListener, TextListener, InputMethodListener, HierarchyListener, HierarchyBoundsListener, MouseWheelListener
AWTEventMulticaster实现高效的线程安全多播事件在
java.awt.event包中定义的AWT事件调度。
下面的示例演示如何使用这个类:
public myComponent extends Component {
ActionListener actionListener = null;
public synchronized void addActionListener(ActionListener l) {
actionListener = AWTEventMulticaster.add(actionListener, l);
}
public synchronized void removeActionListener(ActionListener l) {
actionListener = AWTEventMulticaster.remove(actionListener, l);
}
public void processEvent(AWTEvent e) {
// when event occurs which causes "action" semantic
ActionListener listener = actionListener;
if (listener != null) {
listener.actionPerformed(new ActionEvent());
}
}
}
要注意的重要一点是对
add和
remove方法的第一个参数是现场维护的听众。此外,你必须指定的
add和
remove方法结果的现场维护的听众。
AWTEventMulticaster是一对EventListeners被设置在施工期实施。AWTEventMulticaster是不变的。的add和remove方法不改变AWTEventMulticaster无论如何。如果有必要,一个新的AWTEventMulticaster创建。这样,在事件调度的过程中添加和删除侦听器是安全的。然而,在事件调度操作过程中添加的事件侦听器没有通知当前正在发送的事件。
所有的add方法允许null参数。如果第一个参数是null,第二个参数是返回。如果第一个参数不null和第二null,第一个参数是返回。如果参数是一个新的AWTEventMulticaster non-null,使用两个参数创建并返回。
为remove方法需要两个参数,下面是返回:
null,如果第一个参数是null,或参数等,通过==。AWTEventMulticaster实例。remove(EventListener)对第一个参数的结果,对remove(EventListener)方法提供第二。摆动使类似的逻辑EventListenerList使用。参考它的细节。
EventListenerList
| Modifier and Type | Field and Description |
|---|---|
protected EventListener |
a |
protected EventListener |
b |
| Modifier | Constructor and Description |
|---|---|
protected |
AWTEventMulticaster(EventListener a, EventListener b)
创建一个事件链与listener-b. listener-a多路广播的情况
|
| Modifier and Type | Method and Description |
|---|---|
void |
actionPerformed(ActionEvent e)
处理事件的方式调用actionPerformed方法对listener-a和listener-b.
|
static ActionListener |
add(ActionListener a, ActionListener b)
增加了action-listener-a与action-listener-b并返回产生的组播侦听者。
|
static AdjustmentListener |
add(AdjustmentListener a, AdjustmentListener b)
增加了adjustment-listener-a与adjustment-listener-b并返回产生的组播侦听者。
|
static ComponentListener |
add(ComponentListener a, ComponentListener b)
增加了component-listener-a与component-listener-b并返回产生的组播侦听者。
|
static ContainerListener |
add(ContainerListener a, ContainerListener b)
增加了container-listener-a与container-listener-b并返回产生的组播侦听者。
|
static FocusListener |
add(FocusListener a, FocusListener b)
增加了focus-listener-a与focus-listener-b并返回产生的组播侦听者。
|
static HierarchyBoundsListener |
add(HierarchyBoundsListener a, HierarchyBoundsListener b)
增加了hierarchy-bounds-listener-a与hierarchy-bounds-listener-b并返回产生的组播侦听者。
|
static HierarchyListener |
add(HierarchyListener a, HierarchyListener b)
增加了hierarchy-listener-a与hierarchy-listener-b并返回产生的组播侦听者。
|
static InputMethodListener |
add(InputMethodListener a, InputMethodListener b)
增加了input-method-listener-a与input-method-listener-b并返回产生的组播侦听者。
|
static ItemListener |
add(ItemListener a, ItemListener b)
增加了item-listener-a与item-listener-b并返回产生的组播侦听者。
|
static KeyListener |
add(KeyListener a, KeyListener b)
增加了key-listener-a与key-listener-b并返回产生的组播侦听者。
|
static MouseListener |
add(MouseListener a, MouseListener b)
增加了mouse-listener-a与mouse-listener-b并返回产生的组播侦听者。
|
static MouseMotionListener |
add(MouseMotionListener a, MouseMotionListener b)
增加了mouse-motion-listener-a与mouse-motion-listener-b并返回产生的组播侦听者。
|
static MouseWheelListener |
add(MouseWheelListener a, MouseWheelListener b)
增加了mouse-wheel-listener-a与mouse-wheel-listener-b并返回产生的组播侦听者。
|
static TextListener |
add(TextListener a, TextListener b) |
static WindowFocusListener |
add(WindowFocusListener a, WindowFocusListener b)
增加了window-focus-listener-a与window-focus-listener-b并返回产生的组播侦听者。
|
static WindowListener |
add(WindowListener a, WindowListener b)
增加了window-listener-a与window-listener-b并返回产生的组播侦听者。
|
static WindowStateListener |
add(WindowStateListener a, WindowStateListener b)
增加了window-state-listener-a与window-state-listener-b并返回产生的组播侦听者。
|
protected static EventListener |
addInternal(EventListener a, EventListener b)
返回产生的组播侦听器添加listener-a和listener-b一起。
|
void |
adjustmentValueChanged(AdjustmentEvent e)
处理adjustmentvaluechanged事件通过调用adjustmentvaluechanged方法对listener-a和listener-b.
|
void |
ancestorMoved(HierarchyEvent e)
处理ancestormoved事件通过调用ancestormoved方法对listener-a和listener-b.
|
void |
ancestorResized(HierarchyEvent e)
处理ancestorresized事件通过调用ancestorresized方法对listener-a和listener-b.
|
void |
caretPositionChanged(InputMethodEvent e)
处理caretpositionchanged事件通过调用caretpositionchanged方法对listener-a和listener-b.
|
void |
componentAdded(ContainerEvent e)
处理事件componentadded容器通过调用componentadded方法对listener-a和listener-b.
|
void |
componentHidden(ComponentEvent e)
处理componenthidden事件通过调用componenthidden方法对listener-a和listener-b.
|
void |
componentMoved(ComponentEvent e)
处理componentmoved事件通过调用componentmoved方法对listener-a和listener-b.
|
void |
componentRemoved(ContainerEvent e)
处理事件componentremoved容器通过调用componentremoved方法对listener-a和listener-b.
|
void |
componentResized(ComponentEvent e)
处理componentresized事件通过调用componentresized方法对listener-a和listener-b.
|
void |
componentShown(ComponentEvent e)
处理componentshown事件通过调用componentshown方法对listener-a和listener-b.
|
void |
focusGained(FocusEvent e)
处理focusgained事件通过调用focusgained方法对listener-a和listener-b.
|
void |
focusLost(FocusEvent e)
处理focuslost事件通过调用focuslost方法对listener-a和listener-b.
|
static <T extends EventListener> |
getListeners(EventListener l, 类<T> listenerType)
返回所有对象链接的
java.util.EventListener
FooListeners指定数组。
|
void |
hierarchyChanged(HierarchyEvent e)
处理hierarchychanged事件通过调用hierarchychanged方法对listener-a和listener-b.
|
void |
inputMethodTextChanged(InputMethodEvent e)
处理inputmethodtextchanged事件通过调用inputmethodtextchanged方法对listener-a和listener-b.
|
void |
itemStateChanged(ItemEvent e)
处理itemstatechanged事件通过调用itemstatechanged方法对listener-a和listener-b.
|
void |
keyPressed(KeyEvent e)
处理keyPressed事件通过调用keyPressed方法对listener-a和listener-b.
|
void |
keyReleased(KeyEvent e)
处理keyreleased事件通过调用keyreleased方法对listener-a和listener-b.
|
void |
keyTyped(KeyEvent e)
处理keytyped事件通过调用keytyped方法对listener-a和listener-b.
|
void |
mouseClicked(MouseEvent e)
手柄mouseClicked事件调用mouseClicked方法对listener-a和listener-b.
|
void |
mouseDragged(MouseEvent e)
负责处理鼠标拖动事件的事件处理方法通过调用负责处理鼠标拖动事件listener-a和listener-b.
|
void |
mouseEntered(MouseEvent e)
处理mouseentered事件通过调用mouseentered方法对listener-a和listener-b.
|
void |
mouseExited(MouseEvent e)
处理mouseexited事件通过调用mouseexited方法对listener-a和listener-b.
|
void |
mouseMoved(MouseEvent e)
负责处理鼠标移动事件的事件处理方法通过调用负责处理鼠标移动事件listener-a和listener-b.
|
void |
mousePressed(MouseEvent e)
处理mousePressed事件通过调用mousePressed方法对listener-a和listener-b.
|
void |
mouseReleased(MouseEvent e)
负责处理鼠标释放事件的事件处理方法通过调用负责处理鼠标释放事件listener-a和listener-b.
|
void |
mouseWheelMoved(MouseWheelEvent e)
处理mousewheelmoved事件通过调用mousewheelmoved方法对listener-a和listener-b.
|
static ActionListener |
remove(ActionListener l, ActionListener oldl)
从action-listener-l除去旧的监听行动并返回产生的组播侦听者。
|
static AdjustmentListener |
remove(AdjustmentListener l, AdjustmentListener oldl)
从adjustment-listener-l除去旧的调整听众并返回产生的组播侦听者。
|
static ComponentListener |
remove(ComponentListener l, ComponentListener oldl)
从component-listener-l除去旧的组件侦听器和返回产生的组播侦听者。
|
static ContainerListener |
remove(ContainerListener l, ContainerListener oldl)
从container-listener-l移除旧集装箱的倾听者并返回产生的组播侦听者。
|
protected EventListener |
remove(EventListener oldl)
从多路广播移除侦听器。
|
static FocusListener |
remove(FocusListener l, FocusListener oldl)
从focus-listener-l除去旧的专注的听众和返回产生的组播侦听者。
|
static HierarchyBoundsListener |
remove(HierarchyBoundsListener l, HierarchyBoundsListener oldl)
从hierarchy-bounds-listener-l除去旧的等级界限的倾听者并返回产生的组播侦听者。
|
static HierarchyListener |
remove(HierarchyListener l, HierarchyListener oldl)
从hierarchy-listener-l除去旧的层次的听众并返回产生的组播侦听者。
|
static InputMethodListener |
remove(InputMethodListener l, InputMethodListener oldl)
从input-method-listener-l除去旧的输入法的听众并返回产生的组播侦听者。
|
static ItemListener |
remove(ItemListener l, ItemListener oldl)
从item-listener-l删除旧项目的听众并返回产生的组播侦听者。
|
static KeyListener |
remove(KeyListener l, KeyListener oldl)
从key-listener-l除去旧的关键听众并返回产生的组播侦听者。
|
static MouseListener |
remove(MouseListener l, MouseListener oldl)
从mouse-listener-l除去旧的鼠标监听并返回产生的组播侦听者。
|
static MouseMotionListener |
remove(MouseMotionListener l, MouseMotionListener oldl)
从mouse-motion-listener-l除去旧的鼠标运动的听众并返回产生的组播侦听者。
|
static MouseWheelListener |
remove(MouseWheelListener l, MouseWheelListener oldl)
从mouse-wheel-listener-l除去旧的鼠标滚轮侦听器和返回产生的组播侦听者。
|
static TextListener |
remove(TextListener l, TextListener oldl) |
static WindowFocusListener |
remove(WindowFocusListener l, WindowFocusListener oldl)
除去旧的窗口焦点的听众从window-focus-listener-l并返回产生的组播侦听者。
|
static WindowListener |
remove(WindowListener l, WindowListener oldl)
从window-listener-l除去旧的窗口监听器返回产生的组播侦听者。
|
static WindowStateListener |
remove(WindowStateListener l, WindowStateListener oldl)
从window-state-listener-l除去旧的窗口状态的听众并返回产生的组播侦听者。
|
protected static EventListener |
removeInternal(EventListener l, EventListener oldl)
返回产生的组播侦听者从listener-l.清除旧的听众后
|
protected static void |
save(ObjectOutputStream s, String k, EventListener l) |
protected void |
saveInternal(ObjectOutputStream s, String k) |
void |
textValueChanged(TextEvent e)
当文本的值已更改时调用。
|
void |
windowActivated(WindowEvent e)
处理windowactivated事件通过调用windowactivated方法对listener-a和listener-b.
|
void |
windowClosed(WindowEvent e)
处理windowclosed事件通过调用windowclosed方法对listener-a和listener-b.
|
void |
windowClosing(WindowEvent e)
处理windowclosing事件通过调用windowclosing方法对listener-a和listener-b.
|
void |
windowDeactivated(WindowEvent e)
处理windowdeactivated事件通过调用windowdeactivated方法对listener-a和listener-b.
|
void |
windowDeiconified(WindowEvent e)
处理windowdeiconfied事件通过调用windowdeiconified方法对listener-a和listener-b.
|
void |
windowGainedFocus(WindowEvent e)
处理windowgainedfocus事件通过调用windowgainedfocus方法对listener-a和listener-b.
|
void |
windowIconified(WindowEvent e)
处理windowiconified事件通过调用windowiconified方法对listener-a和listener-b.
|
void |
windowLostFocus(WindowEvent e)
处理windowlostfocus事件通过调用windowlostfocus方法对listener-a和listener-b.
|
void |
windowOpened(WindowEvent e)
处理windowopened事件通过调用windowopened方法对listener-a和listener-b.
|
void |
windowStateChanged(WindowEvent e)
处理windowstatechanged事件通过调用windowstatechanged方法对listener-a和listener-b.
|
protected final EventListener a
protected final EventListener b
protected AWTEventMulticaster(EventListener a, EventListener b)
a和
b不应
null,虽然实现可以选择是否把
NullPointerException那么不同。
a - listener-a
b - listener-b
protected EventListener remove(EventListener oldl)
返回包含所有的听众在多路广播多路广播的oldl所有出现的异常。如果产生的多路广播只包含一个普通听众的老听众可能会返回。如果产生的多路广播是空的,然后null可能还不是。
如果oldl是null不抛出异常。
oldl -听者被删除
public void componentResized(ComponentEvent e)
componentResized 接口
ComponentListener
e -组件的事件
public void componentMoved(ComponentEvent e)
componentMoved 接口
ComponentListener
e -组件的事件
public void componentShown(ComponentEvent e)
componentShown 接口
ComponentListener
e -组件的事件
public void componentHidden(ComponentEvent e)
componentHidden 接口
ComponentListener
e -组件的事件
public void componentAdded(ContainerEvent e)
componentAdded 接口
ContainerListener
e -组件的事件
public void componentRemoved(ContainerEvent e)
componentRemoved 接口
ContainerListener
e -组件的事件
public void focusGained(FocusEvent e)
focusGained 接口
FocusListener
e -焦点事件
public void focusLost(FocusEvent e)
focusLost 接口
FocusListener
e -焦点事件
public void keyTyped(KeyEvent e)
keyTyped 接口
KeyListener
e的关键事件
public void keyPressed(KeyEvent e)
keyPressed 接口
KeyListener
e的关键事件
public void keyReleased(KeyEvent e)
keyReleased 接口
KeyListener
e的关键事件
public void mouseClicked(MouseEvent e)
mouseClicked 接口
MouseListener
e -鼠标事件
public void mousePressed(MouseEvent e)
mousePressed 接口
MouseListener
e -鼠标事件
public void mouseReleased(MouseEvent e)
mouseReleased 接口
MouseListener
e -鼠标事件
public void mouseEntered(MouseEvent e)
mouseEntered 接口
MouseListener
e -鼠标事件
public void mouseExited(MouseEvent e)
mouseExited 接口
MouseListener
e -鼠标事件
public void mouseDragged(MouseEvent e)
mouseDragged 接口
MouseMotionListener
e -鼠标事件
public void mouseMoved(MouseEvent e)
mouseMoved 接口
MouseMotionListener
e -鼠标事件
public void windowOpened(WindowEvent e)
windowOpened 接口
WindowListener
e -窗口事件
public void windowClosing(WindowEvent e)
windowClosing 接口
WindowListener
e -窗口事件
public void windowClosed(WindowEvent e)
windowClosed 接口
WindowListener
e -窗口事件
public void windowIconified(WindowEvent e)
windowIconified 接口
WindowListener
e -窗口事件
Frame.setIconImage(java.awt.Image)
public void windowDeiconified(WindowEvent e)
windowDeiconified 接口
WindowListener
e -窗口事件
public void windowActivated(WindowEvent e)
windowActivated 接口
WindowListener
e -窗口事件
public void windowDeactivated(WindowEvent e)
windowDeactivated 接口
WindowListener
e -窗口事件
public void windowStateChanged(WindowEvent e)
windowStateChanged 接口
WindowStateListener
e -窗口事件
public void windowGainedFocus(WindowEvent e)
windowGainedFocus 接口
WindowFocusListener
e -窗口事件
public void windowLostFocus(WindowEvent e)
windowLostFocus 接口
WindowFocusListener
e -窗口事件
public void actionPerformed(ActionEvent e)
actionPerformed 接口
ActionListener
e -动作事件
public void itemStateChanged(ItemEvent e)
itemStateChanged 接口
ItemListener
e -项目活动
public void adjustmentValueChanged(AdjustmentEvent e)
adjustmentValueChanged 接口
AdjustmentListener
e -调整事件
public void textValueChanged(TextEvent e)
TextListener
textValueChanged 接口
TextListener
public void inputMethodTextChanged(InputMethodEvent e)
inputMethodTextChanged 接口
InputMethodListener
e -项目活动
public void caretPositionChanged(InputMethodEvent e)
caretPositionChanged 接口
InputMethodListener
e -项目活动
public void hierarchyChanged(HierarchyEvent e)
hierarchyChanged 接口
HierarchyListener
e -项目活动
HierarchyEvent.getChangeFlags()
public void ancestorMoved(HierarchyEvent e)
ancestorMoved 接口
HierarchyBoundsListener
e -项目活动
public void ancestorResized(HierarchyEvent e)
ancestorResized 接口
HierarchyBoundsListener
e -项目活动
public void mouseWheelMoved(MouseWheelEvent e)
mouseWheelMoved 接口
MouseWheelListener
e -鼠标事件
MouseWheelEvent
public static ComponentListener add(ComponentListener a, ComponentListener b)
a - component-listener-a
b - component-listener-b
public static ContainerListener add(ContainerListener a, ContainerListener b)
a - container-listener-a
b - container-listener-b
public static FocusListener add(FocusListener a, FocusListener b)
a - focus-listener-a
b - focus-listener-b
public static KeyListener add(KeyListener a, KeyListener b)
a - key-listener-a
b - key-listener-b
public static MouseListener add(MouseListener a, MouseListener b)
a - mouse-listener-a
b - mouse-listener-b
public static MouseMotionListener add(MouseMotionListener a, MouseMotionListener b)
a - mouse-motion-listener-a
b - mouse-motion-listener-b
public static WindowListener add(WindowListener a, WindowListener b)
a - window-listener-a
b - window-listener-b
public static WindowStateListener add(WindowStateListener a, WindowStateListener b)
a - window-state-listener-a
b - window-state-listener-b
public static WindowFocusListener add(WindowFocusListener a, WindowFocusListener b)
a - window-focus-listener-a
b - window-focus-listener-b
public static ActionListener add(ActionListener a, ActionListener b)
a - action-listener-a
b - action-listener-b
public static ItemListener add(ItemListener a, ItemListener b)
a - item-listener-a
b - item-listener-b
public static AdjustmentListener add(AdjustmentListener a, AdjustmentListener b)
a - adjustment-listener-a
b - adjustment-listener-b
public static TextListener add(TextListener a, TextListener b)
public static InputMethodListener add(InputMethodListener a, InputMethodListener b)
a - input-method-listener-a
b - input-method-listener-b
public static HierarchyListener add(HierarchyListener a, HierarchyListener b)
a - hierarchy-listener-a
b - hierarchy-listener-b
public static HierarchyBoundsListener add(HierarchyBoundsListener a, HierarchyBoundsListener b)
a - hierarchy-bounds-listener-a
b - hierarchy-bounds-listener-b
public static MouseWheelListener add(MouseWheelListener a, MouseWheelListener b)
a - mouse-wheel-listener-a
b - mouse-wheel-listener-b
public static ComponentListener remove(ComponentListener l, ComponentListener oldl)
l - component-listener-l
oldl -组件的听众被删除
public static ContainerListener remove(ContainerListener l, ContainerListener oldl)
l - container-listener-l
oldl -容器的听众被删除
public static FocusListener remove(FocusListener l, FocusListener oldl)
l - focus-listener-l
oldl焦点-听众被删除
public static KeyListener remove(KeyListener l, KeyListener oldl)
l - key-listener-l
oldl -关键的听众被删除
public static MouseListener remove(MouseListener l, MouseListener oldl)
l - mouse-listener-l
oldl -鼠标监听器被删除
public static MouseMotionListener remove(MouseMotionListener l, MouseMotionListener oldl)
l - mouse-motion-listener-l
oldl -鼠标运动的听众被删除
public static WindowListener remove(WindowListener l, WindowListener oldl)
l - window-listener-l
oldl -窗口的监听器被删除
public static WindowStateListener remove(WindowStateListener l, WindowStateListener oldl)
l - window-state-listener-l
oldl -窗口状态的听众被删除
public static WindowFocusListener remove(WindowFocusListener l, WindowFocusListener oldl)
l - window-focus-listener-l
oldl -窗口焦点的听众被删除
public static ActionListener remove(ActionListener l, ActionListener oldl)
l - action-listener-l
oldl的监听行动被删除
public static ItemListener remove(ItemListener l, ItemListener oldl)
l - item-listener-l
oldl -项目的听众被删除
public static AdjustmentListener remove(AdjustmentListener l, AdjustmentListener oldl)
l - adjustment-listener-l
oldl -调整听众被删除
public static TextListener remove(TextListener l, TextListener oldl)
public static InputMethodListener remove(InputMethodListener l, InputMethodListener oldl)
l - input-method-listener-l
oldl -输入法的听众被删除
public static HierarchyListener remove(HierarchyListener l, HierarchyListener oldl)
l - hierarchy-listener-l
oldl -层次的听众被删除
public static HierarchyBoundsListener remove(HierarchyBoundsListener l, HierarchyBoundsListener oldl)
l - hierarchy-bounds-listener-l
oldl -层次界听众被删除
public static MouseWheelListener remove(MouseWheelListener l, MouseWheelListener oldl)
l - mouse-wheel-listener-l
oldl -鼠标轮的听众被删除
protected static EventListener addInternal(EventListener a, EventListener b)
a事件listener-a
b事件listener-b
protected static EventListener removeInternal(EventListener l, EventListener oldl)
l -听众被删除
oldl -听众被删除
protected void saveInternal(ObjectOutputStream s, String k) throws IOException
IOException
protected static void save(ObjectOutputStream s, String k, EventListener l) throws IOException
IOException
public static <T extends EventListener> T[] getListeners(EventListener l, 类<T> listenerType)
java.util.EventListener
FooListeners指定数组。
FooListeners捆绑用
addFooListener方法
AWTEventMulticaster。如果一个
null监听器指定,此方法将返回空数组。如果指定的听众是不是
AWTEventMulticaster实例,该方法返回一个数组只包含指定侦听器。如果没有这样的侦听器被链接,则该方法返回一个空数组。
l -指定
java.util.EventListener
listenerType -听众的类型要求;这个参数应该指定一个接口,从
java.util.EventListener
FooListeners数组,或一个空数组如果没有这样的听众已被指定的组播侦听者
NullPointerException -如果指定
listenertype参数
null
ClassCastException -如果
listenerType不指定一个类或接口实现
java.util.EventListener
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.