public class Button extends Component implements Accessible
Quit
”按钮显示在Solaris操作系统下的三种观点:
第一个视图显示了按钮,因为它通常出现。第二个视图显示了当它有输入焦点时的按钮。它的轮廓是黑暗的,让用户知道它是一个活跃的对象。当用户在按钮上单击鼠标时,第三视图显示该按钮,因此请求执行一个动作。
点击一个鼠标手势与ActionEvent
一实例关联,发出的是当鼠标按下和释放都在按钮。如果应用程序想知道当按钮被按下而不公布,作为一个单独的动作,它可以processMouseEvent
,或可登记本身作为一个叫addMouseListener
鼠标事件的监听器。这些方法都是由Component
,所有组件的抽象类。
当一个按钮被按下和释放,AWT将ActionEvent
实例按钮,在按钮调用processEvent
。按钮的processEvent
方法接收的按钮,所有的事件;通过行为事件在调用自己的processActionEvent
方法。后一种方法将操作事件传递给已注册的由该按钮产生的动作事件的任何动作侦听器。
如果一个应用程序需要执行基于按钮的按下和释放一些行动,应该实行ActionListener
和登记从这个按钮接收事件的新听众,通过调用按钮的addActionListener
方法。该应用程序可以使用该按钮的动作命令作为消息传递协议。
Modifier and Type | Class and Description |
---|---|
protected class |
Button.AccessibleAWTButton
这个类实现了对
Button 类可访问性支持。
|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
Button()
用一个空字符串构造一个它的标签的按钮。
|
Button(String label)
用指定的标签构造一个按钮。
|
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(ActionListener l)
添加指定的操作侦听器从该按钮接收动作事件。
|
void |
addNotify()
创建按钮的对等点。
|
AccessibleContext |
getAccessibleContext()
获取与此相关的
AccessibleContext
Button 。
|
String |
getActionCommand()
返回由此按钮触发的动作事件的命令名称。
|
ActionListener[] |
getActionListeners()
返回在这个按钮上注册的所有操作侦听器的数组。
|
String |
getLabel()
获取此按钮的标签。
|
<T extends EventListener> |
getListeners(类<T> listenerType)
返回对象的当前注册为
FooListener s在这
Button 数组。
|
protected String |
paramString()
返回一个字符串,表示此
Button 状态。
|
protected void |
processActionEvent(ActionEvent e)
过程行动事件发生在这个按钮上派遣他们任何注册
ActionListener 对象。
|
protected void |
processEvent(AWTEvent e)
在这个按钮上处理事件。
|
void |
removeActionListener(ActionListener l)
移除指定的动作侦听器,以便它不再从该按钮接收动作事件。
|
void |
setActionCommand(String command)
设置由此按钮触发的动作事件的命令名。
|
void |
setLabel(String label)
将按钮的标签设置为指定的字符串。
|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
public Button() throws HeadlessException
HeadlessException
-如果graphicsenvironment isheadless()返回true。
GraphicsEnvironment.isHeadless()
public Button(String label) throws HeadlessException
label
-一个按钮的字符串标签,无标签或
null
HeadlessException
-如果graphicsenvironment isheadless()返回true。
GraphicsEnvironment.isHeadless()
public void addNotify()
addNotify
方法重写,继承类
Component
Toolkit.createButton(java.awt.Button)
,
Component.getToolkit()
public String getLabel()
null
如果按钮没有标签。
setLabel(java.lang.String)
public void setLabel(String label)
label
-新的标签,或
null
如果按钮没有标签。
getLabel()
public void setActionCommand(String command)
command
-用来设置按钮的动作命令字符串。如果字符串是
null
然后行动命令设置相匹配的按钮标签。
ActionEvent
public String getActionCommand()
null
(默认)那么这个方法返回按钮的标签。
public void addActionListener(ActionListener l)
指对AWT的线程模型的细节AWT Threading Issues。
l
的监听行动
removeActionListener(java.awt.event.ActionListener)
,
getActionListeners()
,
ActionListener
public void removeActionListener(ActionListener l)
指对AWT的线程模型的细节AWT Threading Issues。
l
的监听行动
addActionListener(java.awt.event.ActionListener)
,
getActionListeners()
,
ActionListener
public ActionListener[] getActionListeners()
ActionListener
s或空数组如果没有行动的听众正在注册
addActionListener(java.awt.event.ActionListener)
,
removeActionListener(java.awt.event.ActionListener)
,
ActionListener
public <T extends EventListener> T[] getListeners(类<T> listenerType)
FooListener
s在这
Button
数组。
FooListener
s使用
addFooListener
方法注册。如果没有这样
您可以指定一个类的listenerType
字面的说法,如FooListener.class
。例如,你可以查询其监听行动与下面的代码Button
b
:
ALS功能[ ] =(action [ ])(b.getlisteners(action。类));听众的存在,此方法将返回空数组。
getListeners
方法重写,继承类
Component
listenerType
-听众的类型要求;这个参数应该指定一个接口,从
java.util.EventListener
FooListener
s数组,或一个空数组如果没有这样的听众已添加
ClassCastException
-如果
listenerType
不指定一个类或接口实现
java.util.EventListener
getActionListeners()
protected void processEvent(AWTEvent e)
ActionEvent
实例,该方法调用
processActionEvent
方法。否则,它调用父类的
processEvent
上。
注意,如果参数是null
行为是不可能导致异常。
processEvent
方法重写,继承类
Component
e
-事件
ActionEvent
,
processActionEvent(java.awt.event.ActionEvent)
protected void processActionEvent(ActionEvent e)
ActionListener
对象。
此方法不被调用,除非为这个按钮启用了动作事件。当下列情况之一发生时,启用了动作事件:
ActionListener
对象是通过addActionListener
注册。enableEvents
。注意,如果参数是null
行为是不可能导致异常。
e
-动作事件
ActionListener
,
addActionListener(java.awt.event.ActionListener)
,
Component.enableEvents(long)
protected String paramString()
Button
状态。这种方法的目的是用于调试目的,其含量和返回的字符串格式不同的实现可能会有所不同。返回的字符串是空的但可能不
null
。
paramString
方法重写,继承类
Component
public AccessibleContext getAccessibleContext()
AccessibleContext
Button
。按钮,在
AccessibleContext
以一个
AccessibleAWTButton
形式。一个新的
AccessibleAWTButton
实例被创建时。
getAccessibleContext
接口
Accessible
getAccessibleContext
方法重写,继承类
Component
AccessibleAWTButton
作为本
Button
的
AccessibleContext
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.