标签:
public class JTextFieldTest extends JFrame{
private static final long serialVersionUID = 1L;
public JTextFieldTest()
{
setSize(250, 100);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
final JTextField jt=new JTextField("aaa",20);
final JButton jb=new JButton("清除");
cp.add(jb);
cp.add(jt);
jt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jt.setText("触发事件");
}
});
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jt.setText("");
jt.requestFocus();
}
});
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JTextFieldTest();
}
}
标签:
原文地址:http://www.cnblogs.com/douyunqian3520/p/5521599.html