我有这个代码..在这里,当我输入数字“6”在文本字段中,文本应该显示在textarea ..但之后,如果我输入任何其他数字,我希望textarea内容清楚。但是当我执行我的代码时,即使输入不同的数字,textarea的旧内容仍然保留。请帮忙!重置文本区域内容
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);
}
}
我在我的电脑上运行这个例子,如果我输入除“6”之外的其他文本字段(如果我输入“6”,它将textarea设置为“文本”),TextArea会清除 – 2013-04-09 17:44:26
您的意思是你想要TextField被清除? – 2013-04-09 17:45:32
TextArea itseld ..它的工作..但它并不一直工作..特别是当有两个文本区域..是否有我的软件或什么问题? – praveena 2013-04-09 18:00:02