开发者

How to clear the JTextField by clicking JButton [duplicate]

开发者 https://www.devze.com 2023-02-17 09:58 出处:网络
This question already has answers here: Closed 10 years ago.开发者_如何学编程 Possible Duplicate:
This question already has answers here: Closed 10 years ago.开发者_如何学编程

Possible Duplicate:

JButton needs to change JTextfield text

How do I clear a JTextField when a JButton is clicked?


Looking for EventHandling, ActionListener?

or code?

JButton b = new JButton("Clear");
b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        textfield.setText("");
        //textfield.setText(null); //or use this
    }
});

Also See
How to Use Buttons

0

精彩评论

暂无评论...
验证码 换一张
取 消