public class FocusEvent extends ComponentEvent
FocusListener
或
FocusAdapter
对象注册到使用组件的
addFocusListener
方法接收这样的事件。(
FocusAdapter
对象实现了
FocusListener
接口。)每个侦听器对象被这
FocusEvent
事件发生时。
有两个层次的焦点事件:永久性和临时性。永久改变焦点事件发生时的重点是直接从一个组件到另一个,如通过电话requestfocus()或用户使用Tab键遍历组件。临时改变焦点事件发生时的重点是暂时失去了一部分作为另一个操作的间接结果,如窗口失活或滚动条拖动。在这种情况下,原来的焦点状态会自动恢复一旦操作完成,或者,对窗口失活的情况下,当窗口被激活。永久和临时的焦点事件使用的是focus_gained和focus_lost事件ID交付;水平可以在事件中使用istemporary()方法区分。
未指定的行为将如果任何特定的FocusEvent
实例的id
参数不在FOCUS_FIRST
到FOCUS_LAST
范围造成的。
FocusAdapter
,
FocusListener
,
Tutorial: Writing a Focus Listener,
Serialized Form
Modifier and Type | Field and Description |
---|---|
static int |
FOCUS_FIRST
用于焦点事件的入侵检测范围的第一个数字。
|
static int |
FOCUS_GAINED
此事件指示该组件现在是焦点所有者。
|
static int |
FOCUS_LAST
用于焦点事件的入侵检测范围的最后一个数字。
|
static int |
FOCUS_LOST
此事件指示该组件不再是焦点所有者。
|
COMPONENT_FIRST, COMPONENT_HIDDEN, COMPONENT_LAST, COMPONENT_MOVED, COMPONENT_RESIZED, COMPONENT_SHOWN
ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, consumed, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, id, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK
source
Constructor and Description |
---|
FocusEvent(Component source, int id)
构建了一个
FocusEvent 对象确定为重点的永久性改变。
|
FocusEvent(Component source, int id, boolean temporary)
构建了一个
FocusEvent 对象并确定是否改变是暂时的。
|
FocusEvent(Component source, int id, boolean temporary, Component opposite)
构建一个与指定的临时状态,相反
Component
FocusEvent 对象。
|
Modifier and Type | Method and Description |
---|---|
Component |
getOppositeComponent()
返回在这个焦点变化中所涉及的其他组件。
|
boolean |
isTemporary()
标识临时或永久性的焦点更改事件。
|
String |
paramString()
返回标识此事件的参数字符串。
|
getComponent
getSource
public static final int FOCUS_FIRST
public static final int FOCUS_LAST
public static final int FOCUS_GAINED
public static final int FOCUS_LOST
public FocusEvent(Component source, int id, boolean temporary, Component opposite)
Component
FocusEvent
对象。相反
Component
参与这个焦点改变其他
Component
。一
FOCUS_GAINED
事件,这是失去焦点的
Component
。一
FOCUS_LOST
事件,这是获得焦点的
Component
。如果焦点发生变化与本机应用程序,在不同的虚拟机的一个java应用程序,或没有其他
Component
,那么相反的
Component
是
null
。
该方法抛出一个IllegalArgumentException
如果source
是null
。
source
-
Component
起源事件
id
-整数表示事件的类型。在允许值的信息,看到
FocusEvent
类的描述
temporary
-等于
true
如果焦点的变化是暂时的;
false
否则
opposite
-参与焦点改变其他组件,或
null
IllegalArgumentException
-如果
source
等于
null
EventObject.getSource()
,
AWTEvent.getID()
,
isTemporary()
,
getOppositeComponent()
public FocusEvent(Component source, int id, boolean temporary)
FocusEvent
对象并确定是否改变是暂时的。
该方法抛出一个IllegalArgumentException
如果source
是null
。
source
-
Component
起源事件
id
-整数表示事件的类型。在允许值的信息,看到
FocusEvent
类的描述
temporary
-等于
true
如果焦点的变化是暂时的;
false
否则
IllegalArgumentException
-如果
source
等于
null
EventObject.getSource()
,
AWTEvent.getID()
,
isTemporary()
public FocusEvent(Component source, int id)
FocusEvent
对象确定为重点的永久性改变。
该方法抛出一个IllegalArgumentException
如果source
是null
。
source
-
Component
起源事件
id
-整数表示事件的类型。在允许值的信息,看到
FocusEvent
类的描述
IllegalArgumentException
-如果
source
等于
null
EventObject.getSource()
,
AWTEvent.getID()
public boolean isTemporary()
true
如果焦点的变化是暂时的;
false
否则
public Component getOppositeComponent()
public String paramString()
paramString
方法重写,继承类
ComponentEvent
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.