import java.awt.*; import java.awt.event.*; public class Test { public static void main (String[] args) { Win win = new Win("Test Window"); } } class Win extends Frame { Win (String name) { // Frameクラスのコンストラクタ(Windowのタイトルを引き渡す) super(name); // Windowの大きさ setSize(400, 300); // レイアウトの変更(行,列,水平ギャップ,垂直ギャップ) setLayout(new GridLayout(2, 1, 5, 10)); //2つのパネルを生成 Panel pn1 = new Panel(); pn1.setLayout(new GridLayout()); add(pn1); Panel pn2 = new Panel(); pn2.setLayout(new GridLayout(2, 2, 5, 10)); add(pn2); // テキストエリア設定 TextArea text_a = new TextArea("Text Area", 5, 10); pn1.add(text_a); // テキストフィールド設定 TextField text_f = new TextField("Text Field"); pn2.add(text_f); // ラベルの設定 Label sp = new Label(); pn2.add(sp); Label lb = new Label("ラベル"); pn2.add(lb); // ボタンの設定 Button bt = new Button("OK"); pn2.add(bt); // ウィンドウを表示 setVisible(true); // イベントアダプタ addWindowListener(new WinEnd()); } /******************************/ /* 上,左,下,右の余白の設定 */ /******************************/ public Insets getInsets() { return new Insets(35, 10, 10, 10); } /************/ /* 終了処理 */ /************/ class WinEnd extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } }