Вопрос

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