import java.awt.*;
import java.awt.event.*;
public class test{
/*
* メイン処理
*/
public static void main(String[] args)
{
Frame f;
Button b1;
Button b2;
TextArea t1;
// フレームを作成する
f = new Frame("test");
f.setSize(240,320);
f.setLayout(null);
// アクションを作成する
allActionListener al = new allActionListener();
// ラベル
Label l1 = new Label("早うちの練習");
l1.setLocation(10,30);
l1.setSize(100,30);
f.add(l1);
Label l2 = new Label("これは、練習文です。");
l2.setLocation(10,120);
l2.setSize(150,30);
f.add(l2);
Label l3 = new Label("以下の文を打とう!");
l3.setLocation(10,70);
l3.setSize(100,30);
f.add(l3);
// テキスト
t1 = new TextArea();
t1.setLocation(10,160);
t1.setSize(150,80);
f.add(t1);
// ボタン作成
b1 = new Button("挑戦する");
b1.setLocation(120,70);
b1.setSize(100,30);
b1.addActionListener(al);
f.add(b1);
// ボタン作成
b2 = new Button("打ち終わった!");
b2.setLocation(10,250);
b2.setSize(100,30);
b2.addActionListener(al);
f.add(b2);
f.setVisible(true);
}
/*
* イベントリスナー
*/
private static class allActionListener
implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
System.out.println(e.getActionCommand());
if ( e.getActionCommand().equals("打ち終わった!")
== true)
{
System.exit(0);
}
}
}
}
|