public class Button extends Component implements Accessible
Quit
ボタンの3つのビューを表します。
1番目のビューは通常の状態のボタンを示します。 2番目のビューは入力フォーカスがあるときのボタンを示します。 ボタンの輪郭は暗くなり、アクティブなオブジェクトであることをユーザーに示します。 3番目のビューは、ユーザーがボタンの上でマウスをクリックし、アクションの実行を要求したときのボタンを示します。
マウスを使ってボタンをクリックするジェスチャは、マウスがボタン上で押されて離されたときに送信されるActionEvent
のインスタンスに関連付けられています。 いつボタンが押されたかを通知される必要はあっても、いつ離されたかを通知される必要がないアプリケーションの場合は、それらを独立したジェスチャとしてprocessMouseEvent
を特殊化したり、addMouseListener
を呼び出すことによりマウス・イベントのリスナーとして自身を登録したりできます。 これらのメソッドは両方とも、すべてのコンポーネントの抽象スーパー・クラスであるComponent
によって定義されています。
ボタンが押されて離されると、AWTはボタンのprocessEvent
を呼び出すことにより、ボタンにActionEvent
のインスタンスを送ります。 ボタンのprocessEvent
メソッドはそのボタンのすべてのイベントを受け取ります。ボタンは自身のprocessActionEvent
メソッドを呼び出すことによってアクション・イベントを渡します。 後者のメソッドはこのボタンによって生成されるアクション・イベントの通知を対象として登録されているアクション・リスナーにアクション・イベントを渡します。
ボタン押されて離されることに基づいてアクションを実行するアプリケーションの場合は、addActionListener
を実装し、ボタンのActionListener
メソッドを呼び出すことにより、このボタンからイベントを受け取るように新しいリスナーを登録する必要があります。 アプリケーションはボタンのアクション・コマンドをメッセージ・プロトコルとして使用します。
修飾子と型 | クラス | 説明 |
---|---|---|
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
コンストラクタ | 説明 |
---|---|
Button() |
そのラベルの空の文字列を持つボタンを構築します。
|
Button(String label) |
指定されたラベルを持つボタンを構築します。
|
修飾子と型 | メソッド | 説明 |
---|---|---|
void |
addActionListener(ActionListener l) |
このボタンからアクション・イベントを受け取るために、指定されたアクション・リスナーを追加します。
|
void |
addNotify() |
ボタンのピアを構築します。
|
AccessibleContext |
getAccessibleContext() |
この
Button に関連付けられたAccessibleContext を取得します。 |
String |
getActionCommand() |
このボタンでトリガーされるアクション・イベントのコマンド名を返します。
|
ActionListener[] |
getActionListeners() |
このボタンに登録されているすべてのアクション・リスナーの配列を返します。
|
String |
getLabel() |
ボタンのラベルを取得します。
|
<T extends EventListener> |
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) |
ボタンのラベルを、指定された文字列に設定します。
|
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のスレッドの問題」を参照してください。
l
- アクション・リスナーremoveActionListener(java.awt.event.ActionListener)
, getActionListeners()
, ActionListener
public void removeActionListener(ActionListener l)
AWTスレッド・モデルの詳細は、「AWTのスレッドの問題」を参照してください。
l
- アクション・リスナーaddActionListener(java.awt.event.ActionListener)
, getActionListeners()
, ActionListener
public ActionListener[] getActionListeners()
ActionListener
。アクション・リスナーが現在登録されていない場合は空の配列addActionListener(java.awt.event.ActionListener)
, removeActionListener(java.awt.event.ActionListener)
, ActionListener
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Button
にFooListener
として現在登録されているすべてのオブジェクトの配列を返します。 FooListener
は、addFooListener
メソッドを使用して登録されます。
FooListener.class
などのクラス・リテラルを使用してlistenerType
引数を指定できます。 たとえば、次のコードを使用して、Button
b
のアクション・リスナーを照会できます。
ActionListener[] als = (ActionListener[])(b.getListeners(ActionListener.class));このようなリスナーがない場合は空の配列を返します。
getListeners
、クラスComponent
listenerType
- 要求されるリスナーの型。java.util.EventListener
の子孫のインタフェースを指定してくださいFooListener
として登録されたすべてのオブジェクトの配列、またはこのようなリスナーが追加されていない場合は空の配列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()
Button
に関連付けられたAccessibleContext
を取得します。 ボタンの場合、AccessibleContext
はAccessibleAWTButton
の形式を取ります。 必要に応じて、新しいAccessibleAWTButton
インスタンスが作成されます。 getAccessibleContext
、インタフェースAccessible
getAccessibleContext
、クラスComponent
Button
のAccessibleContext
として機能するAccessibleAWTButton
バグまたは機能を送信
詳細なAPIリファレンスおよび開発者ドキュメントについては、Java SEのドキュメントを参照してください。 そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Documentation Redistribution Policyも参照してください。