私はこのコードを持っています..ここでテキストフィールドに数字「6」を入力すると、テキストがテキストエリアに表示されます..しかし、その後、他の数字を入力すると、テキストエリアの内容を明確にしたい. しかし、コードを実行すると、別の数値を入力してもテキストエリアの古い内容が残ります。助けてください!
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code="front" width=500 height=500></applet> */
public class front extends Applet implements ActionListener {
String msg="";
TextArea text,text1;
TextField txt;
Button load, enter;
public void init() {
enter=new Button("Enter");
load=new Button("Load");
txt=new TextField(5);
text=new TextArea(10,15);
add(load);
add(text);
add(txt);
add(enter);
load.addActionListener(this);
txt.addActionListener(this);
enter.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str = ae.getActionCommand();
if(str.equals("Load")) {
msg = "You pressed Load";
} else {
if(txt.getText().toString().equals ("6")) {
msg="Set the text for 6";
text.setText("Text");
} else {
msg="Invalid number";
text.setText("");
}
}
repaint();
}
public void paint(Graphics g) {
g.drawString(msg,350,250);
}
}