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) { // JFrameクラスのコンストラクタ super(name); // ウィンドウサイズ setSize(200,200); // レイアウト(null)の設定とボタン Container cP = getContentPane(); cP.setLayout(null); cP.setBackground(Color.white); JButton bt = new JButton("ボタン"); bt.setBackground(Color.cyan); Font f = new Font("MS 明朝", Font.PLAIN, 25); bt.setFont(f); bt.setBounds(40,80,100,50); // 位置,幅,高さ bt.setSize(120, 50); // 大きさ変更 cP.add(bt); // ウィンドウを表示 setVisible(true); // イベントアダプタ addWindowListener(new WinEnd()); } /************/ /* 終了処理 */ /************/ class WinEnd extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } }