- java.lang.Object
-
- java.awt.Component
-
- java.awt.Button
-
- すべての実装されたインタフェース:
ImageObserver,MenuContainer,Serializable,Accessible
public class Button extends Component implements Accessible
このクラスはラベル付きボタンを生成します。 アプリケーションは、ボタンが押されたときにアクションが実行されるようにできます。 このイメージは、Solarisオペレーティング・システムで表示されるQuitボタンの3つのビューを表します。
1番目のビューは通常の状態のボタンを示します。 2番目のビューは入力フォーカスがあるときのボタンを示します。 ボタンの輪郭は暗くなり、アクティブなオブジェクトであることをユーザーに示します。 3番目のビューは、ユーザーがボタンの上でマウスをクリックし、アクションの実行を要求したときのボタンを示します。
マウスを使ってボタンをクリックするジェスチャは、マウスがボタン上で押されて離されたときに送信される
ActionEventのインスタンスに関連付けられています。 いつボタンが押されたかを通知される必要はあっても、いつ離されたかを通知される必要がないアプリケーションの場合は、それらを独立したジェスチャとしてprocessMouseEventを特殊化したり、addMouseListenerを呼び出すことによりマウス・イベントのリスナーとして自身を登録したりできます。 これらのメソッドは両方とも、すべてのコンポーネントの抽象スーパー・クラスであるComponentによって定義されています。ボタンが押されて離されると、AWTはボタンの
processEventを呼び出すことにより、ボタンにActionEventのインスタンスを送ります。 ボタンのprocessEventメソッドはそのボタンのすべてのイベントを受け取ります。ボタンは自身のprocessActionEventメソッドを呼び出すことによってアクション・イベントを渡します。 後者のメソッドはこのボタンによって生成されるアクション・イベントの通知を対象として登録されているアクション・リスナーにアクション・イベントを渡します。ボタン押されて離されることに基づいてアクションを実行するアプリケーションの場合は、
addActionListenerを実装し、ボタンのActionListenerメソッドを呼び出すことにより、このボタンからイベントを受け取るように新しいリスナーを登録する必要があります。 アプリケーションはボタンのアクション・コマンドをメッセージ・プロトコルとして使用します。
-
-
ネストされたクラスのサマリー
ネストされたクラス 修飾子と型 クラス 説明 protected classButton.AccessibleAWTButtonこのクラスはButtonクラスのアクセシビリティ・サポートを実装しています。-
クラス java.awt.Componentで宣言されたネストされたクラス/インタフェース
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
フィールドのサマリー
-
クラス java.awt.Componentで宣言されたフィールド
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
インタフェース java.awt.image.ImageObserverで宣言されたフィールド
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
メソッドのサマリー
修飾子と型 メソッド 説明 voidaddActionListener(ActionListener l)このボタンからアクション・イベントを受け取るために、指定されたアクション・リスナーを追加します。voidaddNotify()ボタンのピアを構築します。AccessibleContextgetAccessibleContext()このButtonに関連付けられているAccessibleContextを取得します。StringgetActionCommand()このボタンでトリガーされるアクション・イベントのコマンド名を返します。ActionListener[]getActionListeners()このボタンに登録されたすべてのアクション・リスナーの配列を返します。StringgetLabel()ボタンのラベルを取得します。<T extends EventListener>
T[]getListeners(クラス<T> listenerType)このButtonにFooListenerとして現在登録されているすべてのオブジェクトの配列を返します。protected StringparamString()このButtonの状態を表す文字列を返します。protected voidprocessActionEvent(ActionEvent e)このボタンで発生するアクション・イベントを、登録されているActionListenerオブジェクトにディスパッチすることによって処理します。protected voidprocessEvent(AWTEvent e)このボタンのイベントを処理します。voidremoveActionListener(ActionListener l)以降このボタンからアクション・イベントを受け取らないように、指定されたアクション・リスナーを削除します。voidsetActionCommand(String command)このボタンによってトリガーされるアクション・イベントのコマンド名を設定します。voidsetLabel(String label)ボタンのラベルを、指定された文字列に設定します。-
クラス java.awt.Componentで宣言されたメソッド
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, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
-
-
-
コンストラクタの詳細
-
Button
public Button() throws HeadlessExceptionそのラベルの空の文字列を持つボタンを構築します。- 例外:
HeadlessException- GraphicsEnvironment.isHeadless()がtrueを返す場合- 関連項目:
GraphicsEnvironment.isHeadless()
-
Button
public Button(String label) throws HeadlessException
指定されたラベルを持つボタンを構築します。- パラメータ:
label- ボタンの文字列ラベル。ラベルがない場合はnull- 例外:
HeadlessException- GraphicsEnvironment.isHeadless()がtrueを返す場合- 関連項目:
GraphicsEnvironment.isHeadless()
-
-
メソッドの詳細
-
addNotify
public void addNotify()
ボタンのピアを構築します。 ボタンのピアは、アプリケーションが機能を変更せずにボタンの外観を変更できるようにします。- オーバーライド:
addNotify、クラス:Component- 関連項目:
Component.getToolkit()
-
getLabel
public String getLabel()
ボタンのラベルを取得します。- 戻り値:
- ボタンのラベル。ボタンにラベルがない場合は
null - 関連項目:
setLabel(java.lang.String)
-
setLabel
public void setLabel(String label)
ボタンのラベルを、指定された文字列に設定します。- パラメータ:
label- 新しいラベル。ボタンにラベルがない場合はnull- 関連項目:
getLabel()
-
setActionCommand
public void setActionCommand(String command)
このボタンによってトリガーされるアクション・イベントのコマンド名を設定します。 デフォルトでは、このアクション・コマンドはボタンのラベルと一致するように設定されます。- パラメータ:
command- ボタンのアクション・コマンドを設定するために使用する文字列。 文字列がnullの場合、アクション・コマンドはボタンのラベルと一致するように設定される- 導入されたバージョン:
- 1.1
- 関連項目:
ActionEvent
-
getActionCommand
public String getActionCommand()
このボタンでトリガーされるアクション・イベントのコマンド名を返します。 コマンド名がnull(デフォルト)の場合、このメソッドはボタンのラベルを返します。- 戻り値:
- このボタンのアクション・コマンド名(またはラベル)
-
addActionListener
public void addActionListener(ActionListener l)
このボタンからアクション・イベントを受け取るために、指定されたアクション・リスナーを追加します。 アクション・イベントは、ユーザーがこのボタンの上でマウス・ボタンを押したり、離したりしたときに発生します。 lがnullの場合、例外はスローされず、処理も実行されません。AWTスレッド・モデルの詳細は、AWTのスレッドの問題を参照してください。
- パラメータ:
l- アクション・リスナー- 導入されたバージョン:
- 1.1
- 関連項目:
removeActionListener(java.awt.event.ActionListener),getActionListeners(),ActionListener
-
removeActionListener
public void removeActionListener(ActionListener l)
以降このボタンからアクション・イベントを受け取らないように、指定されたアクション・リスナーを削除します。 アクション・イベントは、ユーザーがこのボタンの上でマウス・ボタンを押したり、離したりしたときに発生します。 lがnullの場合、例外はスローされず、処理も実行されません。AWTスレッド・モデルの詳細は、AWTのスレッドの問題を参照してください。
- パラメータ:
l- アクション・リスナー- 導入されたバージョン:
- 1.1
- 関連項目:
addActionListener(java.awt.event.ActionListener),getActionListeners(),ActionListener
-
getActionListeners
public ActionListener[] getActionListeners()
このボタンに登録されたすべてのアクション・リスナーの配列を返します。- 戻り値:
- このボタンのすべての
ActionListener。アクション・リスナーが現在登録されていない場合は空の配列 - 導入されたバージョン:
- 1.4
- 関連項目:
addActionListener(java.awt.event.ActionListener),removeActionListener(java.awt.event.ActionListener),ActionListener
-
getListeners
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- 型パラメータ:
T- リスナーの型- パラメータ:
listenerType- 要求されるリスナーの型。次の下位インタフェースを指定:java.util.EventListener- 戻り値:
- このボタン上で
FooListenerとして登録されたすべてのオブジェクトの配列、またはこのようなリスナーが追加されていない場合は空の配列 - 例外:
ClassCastException-listenerTypeで、java.util.EventListenerを実装するクラスまたはインタフェースが指定されなかった場合- 導入されたバージョン:
- 1.3
- 関連項目:
getActionListeners()
-
processEvent
protected void processEvent(AWTEvent e)
このボタンのイベントを処理します。 イベントがActionEventのインスタンスである場合、このメソッドはprocessActionEventメソッドを呼び出します。 それ以外の場合は、スーパー・クラスのprocessEventを呼び出します。イベント・パラメータが
nullである場合は、動作が未指定のため、例外が発生する可能性があります。- オーバーライド:
processEvent、クラス:Component- パラメータ:
e- イベント- 導入されたバージョン:
- 1.1
- 関連項目:
ActionEvent,processActionEvent(java.awt.event.ActionEvent)
-
processActionEvent
protected void processActionEvent(ActionEvent e)
このボタンで発生するアクション・イベントを、登録されているActionListenerオブジェクトにディスパッチすることによって処理します。このボタンに対してアクション・イベントが使用可能でない場合、このメソッドは呼び出されません。 アクション・イベントは、次のどちらかの場合に使用可能になります。
ActionListenerオブジェクトがaddActionListenerによって登録されている。enableEventsによってアクション・イベントが使用可能になっている。
イベント・パラメータが
nullである場合は、動作が未指定のため、例外が発生する可能性があります。- パラメータ:
e- アクション・イベント- 導入されたバージョン:
- 1.1
- 関連項目:
ActionListener,addActionListener(java.awt.event.ActionListener),Component.enableEvents(long)
-
paramString
protected String paramString()
このButtonの状態を表す文字列を返します。 このメソッドはデバッグ専用であり、返される文字列の内容および形式は実装によって異なる可能性があります。 返される文字列は空でもかまいませんが、nullにはできません。- オーバーライド:
paramString、クラス:Component- 戻り値:
- このボタンのパラメータ文字列
-
getAccessibleContext
@BeanProperty(expert=true, description="The AccessibleContext associated with this Button.") public AccessibleContext getAccessibleContext()
このButtonに関連付けられているAccessibleContextを取得します。 ボタンの場合、AccessibleContextはAccessibleAWTButtonの形式を取ります。 必要に応じて、新しいAccessibleAWTButtonインスタンスが作成されます。- 定義:
getAccessibleContext、インタフェース:Accessible- オーバーライド:
getAccessibleContext、クラス:Component- 戻り値:
- この
ButtonのAccessibleContextとして機能するAccessibleAWTButton - 導入されたバージョン:
- 1.3
-
-