// ボタンを表示する import java.awt.*; import java.awt.event.*; public class Sample3 extends Frame { private Button bt; public static void main(String[] args) { Sample3 sm = new Sample3(); } public Sample3() // コンストラクタ { super("サンプル"); bt = new Button("ようこそ"); // ボタンを作成 bt.setForeground(Color.blue); // 色を設定 bt.setFont(new Font("Serif", Font.BOLD, 24)); // フォントを設定 add(bt); // ボタンを追加 addWindowListener(new SampleWindowListener()); // イベントを受け取る準備 bt.addActionListener(new SampleActionListener()); setSize(250,200); setVisible(true); } class SampleWindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } // ActionListenerはアクションイベントを受け取るためのリスナーインタフェース class SampleActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { bt.setLabel("Javaへ!"); } } } // end of Sample3.java