|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Button
public class Button
此類別創建一個標籤按鈕。當按下該按鈕時,應用程序能執行某項動作。以下圖像描繪了在 Solaris 作業系統下,"Quit" 按鈕所表現的三種視圖:
第一幅視圖展示該按鈕在一般情況下的外觀。第二幅視圖展示該按鈕成為輸入焦點時的外觀。其邊框變黑,讓使用者知道它是一個活動物件。第三幅視圖展示使用者在該按鈕上單擊鼠標,從而請求執行某個動作時該按鈕的外觀。
用鼠標單擊按鈕這一動作與 ActionEvent 的一個實例相關,在按下鼠標和釋放按鈕的時候都會用到該類別。如果應用程序希望知道何時按鈕作為一個單獨動作被按下但未釋放,它可以特殊化 processMouseEvent,或者通過調用 addMouseListener 將自身註冊為鼠標事件的偵聽器。這兩種方法都是由所有元件的抽象父級類別 Component 定義的。
當按下按鈕並釋放時,AWT 通過調用按鈕的 processEvent,將 ActionEvent 的一個實例發送給按鈕。按鈕的 processEvent 方法接收按鈕的所有事件;同時,它通過調用自身的 processActionEvent 方法傳遞一個動作事件。後一種方法將動作事件傳遞給為關注此按鈕產生的動作事件而註冊的任何動作偵聽器。
如果應用程序想要執行基於按下並釋放按鈕的某個動作,則它應該實作 ActionListener 並註冊新的偵聽器,以便通過調用按鈕的 addActionListener 方法來接收發自此按鈕的事件。應用程序可以按訊息傳遞協議使用按鈕的動作命令。
ActionEvent,
ActionListener,
Component.processMouseEvent(java.awt.event.MouseEvent),
Component.addMouseListener(java.awt.event.MouseListener),
序列化表格| 巢狀類別摘要 | |
|---|---|
protected class |
Button.AccessibleAWTButton
此類別實作對 Button 類別的可存取性支持。 |
| 從類別 java.awt.Component 繼承的巢狀類別/介面 |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| 欄位摘要 |
|---|
| 從類別 java.awt.Component 繼承的欄位 |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| 從介面 java.awt.image.ImageObserver 繼承的欄位 |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| 建構子摘要 | |
|---|---|
Button()
建構一個標籤字元串為空的按鈕。 |
|
Button(String label)
建構一個帶指定標籤的按鈕。 |
|
| 方法摘要 | ||
|---|---|---|
void |
addActionListener(ActionListener l)
添加指定的動作偵聽器,以接收發自此按鈕的動作事件。 |
|
void |
addNotify()
創建按鈕的同位體。 |
|
AccessibleContext |
getAccessibleContext()
獲取與此 Button 相關的 AccessibleContext。 |
|
String |
getActionCommand()
返回此按鈕觸發的動作事件的命令名稱。 |
|
ActionListener[] |
getActionListeners()
返回在此按鈕上註冊的所有動作偵聽器的一個陣列。 |
|
String |
getLabel()
獲取此按鈕的標籤。 |
|
|
getListeners(Class<T> listenerType)
返回當前在此 Button 上註冊為 FooListener 的所有物件的陣列。 |
|
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)
將按鈕的標籤設置為指定的字元串。 |
|
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 建構子詳細資訊 |
|---|
public Button()
throws HeadlessException
HeadlessException - 如果 GraphicsEnvironment.isHeadless() 返回 trueGraphicsEnvironment.isHeadless()
public Button(String label)
throws HeadlessException
label - 按鈕的字元串標籤,如果沒有標籤,則為 null
HeadlessException - 如果 GraphicsEnvironment.isHeadless() 返回 trueGraphicsEnvironment.isHeadless()| 方法詳細資訊 |
|---|
public void addNotify()
Component 中的 addNotifyToolkit.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,則動作命令設置為與按鈕標籤相比對。ActionEventpublic String getActionCommand()
null(預設),則此方法返回按鈕的標籤。
public void addActionListener(ActionListener l)
有關 AWT 的執行緒模型的細節資訊,請參閱 AWT 執行緒問題。
l - 動作偵聽器removeActionListener(java.awt.event.ActionListener),
getActionListeners(),
ActionListenerpublic void removeActionListener(ActionListener l)
有關 AWT 的執行緒模型的細節資訊,請參閱 AWT 執行緒問題。
l - 動作偵聽器addActionListener(java.awt.event.ActionListener),
getActionListeners(),
ActionListenerpublic ActionListener[] getActionListeners()
ActionListener;如果當前沒有註冊任何動作偵聽器,則返回一個空陣列。addActionListener(java.awt.event.ActionListener),
removeActionListener(java.awt.event.ActionListener),
ActionListenerpublic <T extends EventListener> T[] getListeners(Class<T> listenerType)
Button 上註冊為 FooListener 的所有物件的陣列。FooListener 是用 addFooListener 方法註冊的。
可以使用 class 文字值(如 FooListener.class)來指定 listenerType 參數。例如,可以使用以下程式碼來查詢 Button b 的動作偵聽器:
ActionListener[] als = (ActionListener[])(b.getListeners(ActionListener.class));如果不存在這樣的偵聽器,則此方法將返回一個空陣列。
Component 中的 getListenerslistenerType - 請求的偵聽器型別;此參數應該指定一個從 java.util.EventListener 繼承的介面
FooListener 註冊的所有物件的陣列;如果尚未添加這樣的偵聽器,則返回一個空陣列
ClassCastException - 如果 listenerType 未指定一個實作 java.util.EventListener 的類別或介面getActionListeners()protected void processEvent(AWTEvent e)
ActionEvent 的一個實例,則此方法將調用 processActionEvent 方法。否則,它調用父級類別的 processEvent 方法。
注意,如果事件參數為 null,則行為未指定,並可能導致一個異常。
Component 中的 processEvente - 事件ActionEvent,
processActionEvent(java.awt.event.ActionEvent)protected void processActionEvent(ActionEvent e)
ActionListener 物件。
只有啟用了此按鈕的動作事件,此方法才有可能被調用。當發生以下事件之一時會啟動動作事件:
addActionListener 註冊了 ActionListener 物件。
enableEvents 啟動了動作事件。
注意,如果事件參數為 null,則行為未指定,並可能導致一個異常。
e - 動作事件ActionListener,
addActionListener(java.awt.event.ActionListener),
Component.enableEvents(long)protected String paramString()
Button 狀態的字元串表示形式。此方法僅在進行除錯的時候使用,對於這兩個實作,返回的字元串的內容和格式可能有所不同。返回的字元串可能為空,但不可能為 null。
Component 中的 paramStringpublic AccessibleContext getAccessibleContext()
Button 相關的 AccessibleContext。對於按鈕,AccessibleContext 採用 AccessibleAWTButton 的形式。如果有必要,創建一個新的 AccessibleAWTButton 實例。
Accessible 中的 getAccessibleContextComponent 中的 getAccessibleContextAccessibleAWTButton,它將充當此 Button 的 AccessibleContext
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。