Samples.java



import java.awt.*;
import java.applet.Applet;

/** awtコンポーネントを含むアプレットSamplesクラス */
public class Samples extends Applet {
        /** awtコンポーネント用の変数の宣言 */ 
        public Panel labelPanel;
        public Label labelLabel;
        public Label label;

        public Panel buttonPanel;
        public Label buttonLabel;
        public Button button;

        public Panel checkboxPanel;
        public Label checkboxLabel;
        public Checkbox checkbox;

        public Panel checkboxGroupPanel;
        public Label checkboxGroupLabel;
        public CheckboxGroup checkboxGroup;
        public Checkbox radio1, radio2, radio3;

        public Panel choicePanel;
        public Label choiceLabel;
        public Choice choice;

        public Panel listPanel;
        public Label listLabel;
        public List list;

        public Panel textFieldPanel;
        public Label textFieldLabel;
        public TextField textField;

        public Panel textAreaPanel;
        public Label textAreaLabel;
        public TextArea textArea;

        public Panel canvasPanel;
        public Label canvasLabel;
        public Canvas canvas;

        /** 初期設定のメソッド */
        public void init() {
        	//ラベル
        	labelPanel = new Panel();
        	labelLabel = new Label("Label:");
        	label = new Label("This is a message.");
        	labelPanel.add( labelLabel );
        	labelPanel.add( label );
        	add( labelPanel );

        	//ボタン
        	buttonPanel = new Panel();
        	buttonLabel = new Label("Button:");
        	button = new Button("Push Me!");
        	buttonPanel.add( buttonLabel );
        	buttonPanel.add( button );
        	add( buttonPanel );

        	//チェックボックス(トグルボタン)
        	checkboxPanel = new Panel();
        	checkboxLabel = new Label("Checkbox:");
        	checkbox = new Checkbox("On/Off");
        	checkboxPanel.add( checkboxLabel );
        	checkboxPanel.add( checkbox );
        	add( checkboxPanel );

        	//ラジオボタン(排他的選択項目)
        	checkboxGroupPanel = new Panel();
        	checkboxGroupLabel = new Label("CheckboxGroup:");
        	checkboxGroup = new CheckboxGroup();
        	radio1 = new Checkbox("dog", checkboxGroup, false);
        	radio2 = new Checkbox("cat", checkboxGroup, false);
        	radio3 = new Checkbox("elephant", checkboxGroup, true);
        	checkboxGroupPanel.add( checkboxGroupLabel );
        	checkboxGroupPanel.add( radio1 );
        	checkboxGroupPanel.add( radio2 );
        	checkboxGroupPanel.add( radio3 );
        	add( checkboxGroupPanel );

        	//ポップアップメニュー
        	choicePanel = new Panel();
        	choiceLabel = new Label("Choice:");
        	choice = new Choice();
        	choice.addItem("apple");
        	choice.addItem("orange");
        	choice.addItem("banana");
        	choice.addItem("melon");
        	choice.addItem("grape");
        	choicePanel.add( choiceLabel );
        	choicePanel.add( choice );
        	add( choicePanel );

        	//スクロールリスト
        	listPanel = new Panel();
        	listLabel = new Label("List:");
        	list = new List(4,false);
        	list.addItem("apple");
        	list.addItem("orange");
        	list.addItem("banana");
        	list.addItem("melon");
        	list.addItem("grape");
        	listPanel.add( listLabel );
        	listPanel.add( list );
        	add( listPanel );

        	//テキストフィールド
        	textFieldPanel = new Panel();
        	textFieldLabel = new Label("TextField:");
        	textField = new TextField(16);
        	textFieldPanel.add( textFieldLabel );
        	textFieldPanel.add( textField );
        	add( textFieldPanel );

        	//テキストフィールド(複数行)
        	textAreaPanel = new Panel();
        	textAreaLabel = new Label("TextArea:");
        	textArea = new TextArea(6, 16);
        	textAreaPanel.add( textAreaLabel );
        	textAreaPanel.add( textArea );
        	add( textAreaPanel );

        	//キャンバス
        	canvasPanel = new Panel();
        	canvasLabel = new Label("Canvas:");
        	canvas = new Canvas();
        	canvas.resize(200, 160);
        	canvas.setBackground( Color.white );
        	canvasPanel.add( canvasLabel );
        	canvasPanel.add( canvas );
        	add( canvasPanel );
        }
}