/*********************************************** テキストボックスのイベント処理 ***********************************************/ import java.applet.*; import java.awt.*; import java.awt.event.*; public class Applet_Textbox_event extends Applet implements ActionListener { Label title,lb1; // ラベルクラスの変数 TextField txt1; // テキストフィールドの変数 int number,n=0; Font f; public void init() { title=new Label("ゲームを始めます"); // ラベルの文字 title.setForeground(Color.red); // 文字色 title.setBackground(Color.yellow); // 背景色 this.add(title); // ラベルの表示  lb1=new Label("数字を入れてください"); this.add(lb1); txt1=new TextField(15); this.add(txt1); txt1.addActionListener(this); // アクションリスナー追加 f=new Font(null,Font.PLAIN,16); } public void paint(Graphics g) { if (n>0){ g.setFont(f); g.setColor(Color.blue); g.drawString(n+" 回目", 30 ,120); g.setColor(Color.red); g.drawString(number+" が入力されました", 30 ,140); } } public void actionPerformed(ActionEvent ev){ number=Integer.parseInt(txt1.getText()); txt1.setText(""); n++; repaint(); } }