CardPanel.java
import java.awt.*;
import java.applet.Applet;
/** ボタンのレイアウトをテストする CardPanel クラス */
public class CardPanel extends Applet {
/** インターフェイスの部品の宣言 */
public Button buttons[];
/** フォントと色の宣言 */
public Font font;
public Color color;
/** ボタンの個数 */
protected static final int MAX_NUM = 12;
/** レイアウト */
public CardLayout lay;
/**
* 初期設定のメソッド
* レイアウトを CardLayoutに設定
*/
public void init() {
lay = new CardLayout(); //レイアウトの生成
setLayout( lay ); //レイアウトの設定
buttons = new Button[MAX_NUM];
color = new Color( 35, 140, 35 );
font = new Font( "TimesRoman", Font.BOLD, 18 );
for( int i=0; i<MAX_NUM; i++ ) {
buttons[i] = new Button( "Button" + i );
buttons[i].setBackground( color );
buttons[i].setForeground( Color.white );
buttons[i].setFont( font );
add( buttons[i] );
}
for( int i=0; i<MAX_NUM; i++ )
lay.next( this ); // コンポーネントを順に表示させる
}
/** アクション処理のメソッド */
public boolean action( Event evt, Object obj ) {
lay.next( this ); // 次のコンポーネントを表示させる
return true;
}
}