Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top