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.FlipBufferStrategyaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, 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, validatepublic Button()
       throws HeadlessException
HeadlessException - GraphicsEnvironment.isHeadless()がtrueを返す場合GraphicsEnvironment.isHeadless()public Button(String label) throws HeadlessException
label - ボタンの文字列ラベル。ラベルがない場合はnullHeadlessException - GraphicsEnvironment.isHeadless()がtrueを返す場合GraphicsEnvironment.isHeadless()public void addNotify()
addNotify、クラスComponentToolkit.createButton(java.awt.Button), Component.getToolkit()public String getLabel()
nullsetLabel(java.lang.String)public void setLabel(String label)
label - 新しいラベル。ボタンにラベルがない場合はnullgetLabel()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メソッドを使用して登録されます。 
 
 FooListener.classなどのクラス・リテラルを使用してlistenerType引数を指定できます。 たとえば、次のコードを使用して、Button bのアクション・リスナーを照会できます。 
 
ActionListener[] als = (ActionListener[])(b.getListeners(ActionListener.class));このようなリスナーがない場合は空の配列を返します。
getListeners、クラスComponentlistenerType - 要求されるリスナーの型。java.util.EventListenerの子孫のインタフェースを指定してくださいFooListenerとして登録されたすべてのオブジェクトの配列、またはこのようなリスナーが追加されていない場合は空の配列ClassCastException - listenerTypeで、java.util.EventListenerを実装するクラスまたはインタフェースが指定されなかった場合getActionListeners()protected void processEvent(AWTEvent e)
ActionEventのインスタンスである場合、このメソッドはprocessActionEventメソッドを呼び出します。 それ以外の場合は、スーパー・クラスのprocessEventを呼び出します。 
 イベント・パラメータがnullである場合は、動作が未指定のため、例外が発生する可能性があります。
processEvent、クラスComponente - イベント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、クラスComponentpublic AccessibleContext getAccessibleContext()
Buttonに関連付けられたAccessibleContextを取得します。 ボタンの場合、AccessibleContextはAccessibleAWTButtonの形式を取ります。 必要に応じて、新しいAccessibleAWTButtonインスタンスが作成されます。 getAccessibleContext、インタフェースAccessiblegetAccessibleContext、クラスComponentButtonの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も参照してください。