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 GridLayout(1, 2, 5, 10)); // 左のパネル JPanel pn1 = new JPanel(); pn1.setLayout(new BoxLayout(pn1, BoxLayout.X_AXIS)); cp.add(pn1); // テキストエリア設定 JTextArea text_a = new JTextArea("Text Area", 10, 30); pn1.add(text_a); // 右のパネル JPanel pn2 = new JPanel(); pn2.setLayout(new BoxLayout(pn2, BoxLayout.Y_AXIS)); cp.add(pn2); // テキストフィールド設定 JTextField text_f = new JTextField("Text Field"); pn2.add(text_f); // ラベルの設定 JLabel lb = new JLabel("BoxLayout"); pn2.add(lb); // ボタンの設定 JButton bt1 = new JButton("OK"); pn2.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); } } }