I have a JButton and I would like the score which is a JTextField to reset to 0 whenever it is pressed.

...
newGameButton.addActionListener(this);
...
public void actionPerformed(ActionEvent e) {
    (add action here)
}

What would I need to do to reset the JTextField to 0? Do you guys know any good websites for learning GUI? Thanks

有帮助吗?

解决方案

Replace (add action here), with myTestField.setText("0"), or score = 0; myTestField.setText(score). Something along those lines.

The official Java tutorials are an excellent place to learn Swing and other related Java techs, it's quite good, so follow that link peeskillet gave you in the comments. There's some good books on Swing too, I would recommend Filthy Rich Clients.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top