JavaTM 2
Platform
Std. Ed. v1.4.0

java.awt
クラス Button

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Button
すべての実装インタフェース:
Accessible, ImageObserver, MenuContainer, Serializable

public class Button
extends Component
implements Accessible

このクラスはラベル付きボタンを生成します。アプリケーションは、ボタンが押されたときにアクションが実行されるようにすることができます。このイメージは、Solaris オペレーティングシステムで表示される Quit ボタンの 3 つのビューを表します。

1 番目のビューは通常の状態のボタンを示します。2 番目のビューは入力フォーカスがあるときのボタンを示します。ボタンの輪郭は暗くなり、アクティブなオブジェクトであることをユーザに示します。3 番目のビューは、ユーザがボタンの上でマウスをクリックし、アクションの実行を要求したときのボタンを示します。

マウスを使ってボタンをクリックするジェスチャーは、マウスがボタン上で押されて離されたときに送信される ActionEvent のインスタンスに関連付けられています。いつボタンが押されたかの通知は必要であるが、いつ離されたかの通知は必要でない場合、アプリケーションは、独立した動作として processMouseEvent を特殊化することも、addMouseListener を呼び出すことによりマウスイベントのリスナーとして自身を登録することもできます。これらのメソッドは両方とも、すべてのコンポーネントの抽象スーパークラスである Component によって定義されます。

ボタンが押されて離されると、AWT はボタンの processEvent を呼び出すことにより、ボタンに ActionEvent のインスタンスを送ります。ボタンの processEvent メソッドはそのボタンのすべてのイベントを受け取ります。ボタンは自身の processActionEvent メソッドを呼び出すことによってアクションイベントを渡します。processActionEvent メソッドはこのボタンによって生成されるアクションイベントの通知を対象として登録されているアクションリスナーにアクションイベントを渡します。

押されて離されるボタンに基づいてアクションを実行する場合、アプリケーションは、ActionListener を実装し、ボタンの addActionListener メソッドを呼び出すことにより、このボタンからイベントを受け取るように新しいリスナーを登録する必要があります。アプリケーションはボタンのアクションコマンドをメッセージプロトコルとして使用します。

導入されたバージョン:
JDK1.0
関連項目:
ActionEvent, ActionListener, Component.processMouseEvent(java.awt.event.MouseEvent), Component.addMouseListener(java.awt.event.MouseListener), 直列化された形式

入れ子クラスの概要
protected  class Button.AccessibleAWTButton
          このクラスは Button クラス用のユーザ補助機能のサポートを実装しています。
 
クラス java.awt.Component から継承した入れ子クラス
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()
          ボタンのラベルを返します。
 EventListener[] getListeners(Class listenerType)
          この ButtonFooListener として現在登録されているすべてのオブジェクトの配列を返します。
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.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, getAlignmentX, getAlignmentY, getBackground, 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, 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, isOpaque, 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, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

Button

public Button()
       throws HeadlessException
ラベルなしのボタンを構築します。

例外:
HeadlessException - GraphicsEnvironment.isHeadless() が true を返す場合
関連項目:
GraphicsEnvironment.isHeadless()

Button

public Button(String label)
       throws HeadlessException
指定されたラベルを持つボタンを構築します。

パラメータ:
label - ボタンの文字列ラベル
例外:
HeadlessException - GraphicsEnvironment.isHeadless() が true を返す場合
関連項目:
GraphicsEnvironment.isHeadless()
メソッドの詳細

addNotify

public void addNotify()
ボタンのピアを構築します。ボタンのピアは、アプリケーションが機能を変更せずにボタンの外観を変更できるようにします。

オーバーライド:
クラス Component 内の addNotify
関連項目:
Toolkit.createButton(java.awt.Button), 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 の場合、アクションコマンドはボタンのラベルと一致するように設定される
導入されたバージョン:
JDK1.1
関連項目:
ActionEvent

getActionCommand

public String getActionCommand()
このボタンでトリガされるアクションイベントのコマンド名を返します。コマンド名が null (デフォルト) の場合、このメソッドはボタンのラベルを返します。


addActionListener

public void addActionListener(ActionListener l)
このボタンからアクションイベントを受け取るために、指定されたアクションリスナーを追加します。アクションイベントは、ユーザがこのボタンの上でマウスボタンを押したり、離したりしたときに発生します。l が null の場合、例外はスローされず、アクションは実行されません。

パラメータ:
l - アクションリスナー
導入されたバージョン:
JDK1.1
関連項目:
removeActionListener(java.awt.event.ActionListener), getActionListeners(), ActionListener

removeActionListener

public void removeActionListener(ActionListener l)
このボタンからアクションイベントを受け取らないように、指定されたアクションリスナーを削除します。アクションイベントは、ユーザがこのボタンの上でマウスボタンを押したり、離したりしたときに発生します。l が null の場合、例外はスローされず、アクションは実行されません。

パラメータ:
l - アクションリスナー
導入されたバージョン:
JDK1.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 EventListener[] getListeners(Class listenerType)
この ButtonFooListener として現在登録されているすべてのオブジェクトの配列を返します。この FooListeneraddFooListener メソッドで登録されたものです。

listenerType 引数は FooListener.class のようなクラスリテラルで指定できます。たとえば、このアクションリスナーに対する Button b の照会は次のコードで行います。

ActionListener[] als = (ActionListener[])(b.getListeners(ActionListener.class));
このようなリスナーがない場合は空の配列を返します。

オーバーライド:
クラス Component 内の getListeners
パラメータ:
listenerType - 要求されるリスナーのタイプ。java.util.EventListener の下位インタフェースを指定
戻り値:
このボタンに FooListener として登録されているすべてのオブジェクトの配列。リスナーが登録されていない場合は空の配列を返す
例外:
ClassCastException - if listenerTypejava.util.EventListener を実装するクラスまたはインタフェースを指定しない場合
導入されたバージョン:
1.3
関連項目:
getActionListeners()

processEvent

protected void processEvent(AWTEvent e)
このボタンに関するイベントを処理します。イベントが ActionEvent のインスタンスである場合、このメソッドは processActionEvent メソッドを呼び出します。そうでない場合は、スーパークラスの processEvent を呼び出します。

イベントパラメータが null の場合の動作は定義されていないため例外がスローされます。

オーバーライド:
クラス Component 内の processEvent
パラメータ:
e - イベント
導入されたバージョン:
JDK1.1
関連項目:
ActionEvent, processActionEvent(java.awt.event.ActionEvent)

processActionEvent

protected void processActionEvent(ActionEvent e)
このボタンで発生するアクションイベントを、登録されている ActionListener オブジェクトにディスパッチすることにより、アクションイベントを処理します。

このボタンに対してアクションイベントが使用可能でない場合、このメソッドは呼び出されません。アクションイベントは、次のどれかの場合に使用可能になります。

イベントパラメータが null の場合の動作は定義されていないため例外がスローされます。

パラメータ:
e - アクションイベント
導入されたバージョン:
JDK1.1
関連項目:
ActionListener, addActionListener(java.awt.event.ActionListener), Component.enableEvents(long)

paramString

protected String paramString()
この Button の状態を表す文字列を返します。このメソッドは、デバッグ専用であり、返される文字列の内容および形式は実装によって異なります。返される文字列は空白の場合がありますが、null にはなりません。

オーバーライド:
クラス Component 内の paramString
戻り値:
このボタンのパラメータ文字列

getAccessibleContext

public AccessibleContext getAccessibleContext()
この Button に関連付けられる AccessibleContext を取得します。AccessibleContext はボタンのフォームを AccessibleAWTButton から取得します。必要な場合は新しい AccessibleAWTButton インスタンスを生成します。

定義:
インタフェース Accessible 内の getAccessibleContext
オーバーライド:
クラス Component 内の getAccessibleContext
戻り値:
この ButtonAccessibleContext として機能する AccessibleAWTButton

JavaTM 2
Platform
Std. Ed. v1.4.0

バグの報告と機能のリクエスト
これ以外の API リファレンスおよび開発者用ドキュメントについては、 Java 2 SDK SE 開発者用ドキュメントを参照してください。 開発者向けの詳細な解説、概念の概要、用語の定義、バグの回避策、 およびコード実例が含まれています。

Java、Java 2D、および JDBC は米国ならびにその他の国における米国 Sun Microsystems, Inc. の商標もしくは登録商標です。
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.