awtコンポーネントのデザイン
コンポーネントのクラスは全て Componentクラスを先祖とします。
/** インターフェイスの部品の宣言 */
public Button greenButton;
/** フォントと色の宣言 */
public Font italicFont;
public Color ivory, forestGreen;
/** 初期設定の関数 */
public void init() {
ivory = new Color( 250, 250, 235 ); // RGB の値を指定
this.setBackground( ivory ); // 背景色の設定
greenButton = new Button( "Green" );
forestGreen = new Color( 35, 140, 35 ); // RGB の値を指定
greenButton.setBackground( forestGreen ); // 背景色の設定
greenButton.setForeground( Color.white ); // 前景色の設定
italicFont = new Font( "TimesRoman", Font.ITALIC, 24 );
greenButton.setFont( italicFont ); // フォントの設定
add( greenButton );
}
}
| 名称 | 機能 |
|---|---|
| setForeground( Color ) | 前景色の設定 |
| Color getForeground() | 前景色の取り出し |
| setBackground( Color ) | 背景色の設定 |
| Color getBackground() | 背景色の取り出し |
| setFont( Font ) | フォントの設定 |
| Font getFont() | フォントの取り出し |
| FontMetrics getFontMetrics() | フォント・メトリックの取り出し *設定はフォントの設定時に 自動的に行われる |
| resize( int, int ) resize( Dimension ) |
サイズの設定 |
| Dimension size() | サイズの取り出し |
| show() | 表示させる |
| hide() | 表示をやめる |
| enable() | 操作可能にする |
| disable() | 操作不可能にする |