GUI程序按钮通过click事件如何实现reset效果?
2个回答
展开全部
import java.awt.*;
import java.awt.event.*;
public class TestTextField {
public static void main (String[] args) {
new Frame1();
}
}
class Frame1 extends Frame {
Frame1() {
Monitor1 m = new Monitor1();
TextField t1 = new TextField();
t1.setEchoChar ('*');
add (t1);
t1.addActionListener (m);
setLocation (400,400);
pack();
setVisible(true);
}
}
class Monitor1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
TextField t1 = (TextField)e.getSource();
System.out.println (t1.getText());
t1.setText (""); 设置每个TextField的值为“”,实现reset效果
}
}
import java.awt.event.*;
public class TestTextField {
public static void main (String[] args) {
new Frame1();
}
}
class Frame1 extends Frame {
Frame1() {
Monitor1 m = new Monitor1();
TextField t1 = new TextField();
t1.setEchoChar ('*');
add (t1);
t1.addActionListener (m);
setLocation (400,400);
pack();
setVisible(true);
}
}
class Monitor1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
TextField t1 = (TextField)e.getSource();
System.out.println (t1.getText());
t1.setText (""); 设置每个TextField的值为“”,实现reset效果
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询