Label
Labelクラスは Componentクラスの直接のサブクラスです。
java.awtパッケージに含まれます。
Labelクラスは、
画面上に一行のテキストを表示する
機能を提供します。
Labelクラスのフィールド
Labelクラスには「左寄せ」「センタリング」「右寄せ」を指定するための
publicな static で finaleな 3個のフィールドが存在します。
- public static final int LEFT
- public static final int CENTER
- public static final int RIGHT
その他、オブジェクトのサイズや色などの基本的な性質は、
Componentクラスから継承し内部に記憶しています。
Labelクラスのメソッド
Labelクラスには、
3個のコンストラクタと5個のpublic なメソッドが用意されています。
コンストラクタ
- public Label()
- public Label(String text)
- public Label(String text, int alignment)
textはラベルに表示される文字列です。
alignmentには上記の「左寄せ」「センタリング」「右寄せ」のいずれかを指定します。
メッソド
- public int getAlignment()
- public synchronized void setAlignment(int alignment)
- public String getText()
- public synchronized void setText(String text)
- public void addNotify()
getText()は表示される文字列を取り出し、
setText()は表示される文字列を設定します。
getAlignment()は「左寄せ」「センタリング」「右寄せ」のいずれかを取り出し、
setAlignment()は「左寄せ」「センタリング」「右寄せ」のいずれかを設定します。
addNotify()は独自のデザインを利用する場合に、その登録のために呼び出します。