import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Test { public static void main (String[] args) { Win win = new Win("Test Window"); } } class Win extends JFrame { Win (String name) { // Frameクラスのコンストラクタ(Windowのタイトルを引き渡す) super(name); // レイアウトの変更 Container cp = getContentPane(); cp.setLayout(new BoxLayout(cp, BoxLayout.X_AXIS)); // テキストエリア設定 JTextArea text_a = new JTextArea("Text Area", 10, 30); cp.add(text_a); // テキストフィールド設定 JTextField text_f = new JTextField("Text Field"); cp.add(text_f); // ラベルの設定 JLabel lb = new JLabel("BoxLayout"); cp.add(lb); // ボタンの設定 JButton bt1 = new JButton("OK"); cp.add(bt1); // Windowの大きさ setSize(400, 300); // ウィンドウを表示 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); } } }