문제

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