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是add和remove方法的第一个参数是add remove器的字段。
另外,您必须将add和remove方法的结果分配给add remove的字段。
AWTEventMulticaster被实施为在建设时设置的一对EventListeners 。 AWTEventMulticaster是不可变的。 add , add和remove方法都不会改变AWTEventMulticaster 。 如有必要,将创建一个新的AWTEventMulticaster 。 通过这种方式,可以安全地在事件调度过程中添加和删除监听器。 但是,在事件调度操作过程中添加的事件侦听器不会被通知当前正在调度的事件。
所有add方法允许null参数。 如果第一个参数是null ,则返回第二个参数。 如果第一个参数不是null ,第二个参数是null ,则返回第一个参数。 如果两个参数是non-null ,新AWTEventMulticaster使用两个参数创建并返回。
对于采用两个参数的remove方法,返回以下内容:
null ,如果第一个参数是null ,或参数相等,则通过==的方式。 AWTEventMulticaster一个实例。 remove(EventListener)结果,将第二个参数提供给remove(EventListener)方法。 Swing使用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-a与listener-b链接起来。
|
| Modifier and Type | Method and Description |
|---|---|
void |
actionPerformed(ActionEvent e)
通过调用listener-a和listener-b上的actionPerformed方法来处理actionPerformed事件。
|
static ActionListener |
add(ActionListener a, ActionListener b)
添加action-listener-a与action-listener-b,并返回生成的组播侦听器。
|
static AdjustmentListener |
add(AdjustmentListener a, AdjustmentListener b)
使用adjust-listener-b添加调整监听器a,并返回生成的组播侦听器。
|
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-b的hierarchy-listener-a并返回生成的组播侦听器。
|
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-b添加key-listener-a,并返回生成的组播侦听器。
|
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)
添加鼠标滚轮监听器a和鼠标滚轮监听器b并返回结果组播侦听器。
|
static TextListener |
add(TextListener a, TextListener b) |
static WindowFocusListener |
add(WindowFocusListener a, WindowFocusListener b)
使用window-focus-listener-b添加window-focus-listener-a,并返回生成的多播侦听器。
|
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)
通过调用listener-a和listener-b上的adjustValueChanged方法来处理adjustValueChanged事件。
|
void |
ancestorMoved(HierarchyEvent e)
通过在listener-a和listener-b上调用ancestorMoved方法来处理ancestorMoved事件。
|
void |
ancestorResized(HierarchyEvent e)
通过调用listener-a和listener-b上的ancestorResized方法来处理ancestorResized事件。
|
void |
caretPositionChanged(InputMethodEvent e)
通过在listener-a和listener-b上调用caretPositionChanged方法处理caretPositionChanged事件。
|
void |
componentAdded(ContainerEvent e)
通过调用listener-a和listener-b上的componentAdded方法来处理componentAdded容器事件。
|
void |
componentHidden(ComponentEvent e)
通过在listener-a和listener-b上调用componentHidden方法来处理componentHidden事件。
|
void |
componentMoved(ComponentEvent e)
通过调用listener-a和listener-b上的componentMoved方法来处理componentMoved事件。
|
void |
componentRemoved(ContainerEvent e)
通过调用listener-a和listener-b上的componentRemoved方法来处理componentRemoved容器事件。
|
void |
componentResized(ComponentEvent e)
通过调用listener-a和listener-b上的componentResized方法来处理componentResized事件。
|
void |
componentShown(ComponentEvent e)
通过调用listener-a和listener-b上的componentShown方法来处理componentShown事件。
|
void |
focusGained(FocusEvent e)
通过在listener-a和listener-b上调用focusGained方法来处理focusGained事件。
|
void |
focusLost(FocusEvent e)
通过在listener-a和listener-b上调用focusLost方法来处理focusLost事件。
|
static <T extends EventListener> |
getListeners(EventListener l, 类<T> listenerType)
返回链作为所有对象的数组
FooListener由该指定S
java.util.EventListener 。
|
void |
hierarchyChanged(HierarchyEvent e)
通过调用listener-a和listener-b上的hierarchyChanged方法来处理hierarchyChanged事件。
|
void |
inputMethodTextChanged(InputMethodEvent e)
通过调用listener-a和listener-b上的inputMethodTextChanged方法来处理inputMethodTextChanged事件。
|
void |
itemStateChanged(ItemEvent e)
通过调用listener-a和listener-b上的itemStateChanged方法来处理itemStateChanged事件。
|
void |
keyPressed(KeyEvent e)
通过在listener-a和listener-b上调用keyPressed方法来处理keyPressed事件。
|
void |
keyReleased(KeyEvent e)
通过调用listener-a和listener-b上的keyReleased方法来处理keyReleased事件。
|
void |
keyTyped(KeyEvent e)
通过在listener-a和listener-b上调用keyTyped方法来处理keyTyped事件。
|
void |
mouseClicked(MouseEvent e)
通过在listener-a和listener-b上调用mouseClicked方法来处理mouseClicked事件。
|
void |
mouseDragged(MouseEvent e)
通过在listener-a和listener-b上调用mouseDragged方法来处理mouseDragged事件。
|
void |
mouseEntered(MouseEvent e)
通过在listener-a和listener-b上调用mouseEntered方法来处理mouseEntered事件。
|
void |
mouseExited(MouseEvent e)
通过在listener-a和listener-b上调用mouseExited方法来处理mouseExited事件。
|
void |
mouseMoved(MouseEvent e)
通过在listener-a和listener-b上调用mouseMoved方法来处理mouseMoved事件。
|
void |
mousePressed(MouseEvent e)
通过在listener-a和listener-b上调用mousePressed方法来处理mousePressed事件。
|
void |
mouseReleased(MouseEvent e)
通过在listener-a和listener-b上调用mouseReleased方法来处理mouseReleased事件。
|
void |
mouseWheelMoved(MouseWheelEvent e)
通过在listener-a和listener-b上调用mouseWheelMoved方法来处理mouseWheelMoved事件。
|
static ActionListener |
remove(ActionListener l, ActionListener oldl)
从action-listener-l中删除旧的action-listener,并返回生成的组播侦听器。
|
static AdjustmentListener |
remove(AdjustmentListener l, AdjustmentListener oldl)
从调整监听器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中删除旧的focus-listener,并返回生成的组播监听器。
|
static HierarchyBoundsListener |
remove(HierarchyBoundsListener l, HierarchyBoundsListener oldl)
从hierarchy-bounds-listener-l中删除旧的hierarchy-bounds-listener,并返回生成的组播监听器。
|
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中删除旧的window-focus-listener,并返回结果组播监听器。
|
static WindowListener |
remove(WindowListener l, WindowListener oldl)
从window-listener-l中删除旧的window-listener,并返回结果组播监听器。
|
static WindowStateListener |
remove(WindowStateListener l, WindowStateListener oldl)
从window-state-listener-l中删除旧的window-state-listener,并返回结果组播监听器。
|
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)
通过调用listener-a和listener-b上的windowActivated方法来处理windowActivated事件。
|
void |
windowClosed(WindowEvent e)
通过调用listener-a和listener-b上的windowClosed方法来处理windowClosed事件。
|
void |
windowClosing(WindowEvent e)
通过调用listener-a和listener-b上的windowClosing方法处理windowClosing事件。
|
void |
windowDeactivated(WindowEvent e)
通过调用listener-a和listener-b上的windowDeactivated方法来处理windowDeactivated事件。
|
void |
windowDeiconified(WindowEvent e)
通过调用listener-a和listener-b上的windowDeiconified方法来处理windowDeiconfied事件。
|
void |
windowGainedFocus(WindowEvent e)
通过调用listener-a和listener-b上的windowGainedFocus方法来处理windowGainedFocus事件。
|
void |
windowIconified(WindowEvent e)
通过调用listener-a和listener-b上的windowIconified方法来处理windowIconified事件。
|
void |
windowLostFocus(WindowEvent e)
通过调用listener-a和listener-b上的windowLostFocus方法来处理windowLostFocus事件。
|
void |
windowOpened(WindowEvent e)
通过调用listener-a和listener-b上的windowOpened方法处理windowOpened事件。
|
void |
windowStateChanged(WindowEvent e)
通过调用listener-a和listener-b上的windowStateChanged方法来处理windowStateChanged事件。
|
protected final EventListener a
protected final EventListener b
protected AWTEventMulticaster(EventListener a, EventListener b)
a和b不应该是null ,尽管在这种情况下,选择是否投掷NullPointerException可能会有所不同。
a - 监听者a
b - listener-b
protected EventListener remove(EventListener oldl)
返回的多维数据包含此多重数据库中的所有侦听器, oldl所有出现的数据oldl 。 如果生成的多维数据集只包含一个常规侦听器,则可能会返回常规侦听器。 如果生成的多维数据集是空的,则可以返回null 。
如果oldl是null则oldl抛出异常。
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 - 调整监听者a
b - 调整监听器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 - 调整监听器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 - 事件监听者a
b - 事件侦听器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)
FooListener由该指定S java.util.EventListener 。
FooListener由AWTEventMulticaster使用addFooListener方法链接。
如果指定了一个null监听器,则此方法返回一个空数组。
如果指定的侦听器不是AWTEventMulticaster的实例, AWTEventMulticaster此方法返回一个仅包含指定侦听器的数组。
如果没有这样的监听器被链接,这个方法返回一个空数组。
l - 指定的
java.util.EventListener
listenerType - 所请求的听众的类型;
此参数应指定从java.util.EventListener下降的java.util.EventListener
FooListener由指定的多播侦听器,或一个空数组S,如果没有这样的侦听被拴由指定的多路广播监听
NullPointerException - 如果指定的
listenertype参数是
null
ClassCastException - 如果
listenerType没有指定实现java.util.EventListener的类或
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.