我試圖在按下按鈕時添加分數,分數顯示在JTextField中,但是當按下按鈕時添加了分數inst,它表示爲0. 我有一個整數字段,用於存儲得分Score ++ does not work
private int score=0;
yesButton = new JButton("True");
panel.add(yesButton);
yesButton.addActionListener(new ActionListener() {
int index = 0;
@Override
public void actionPerformed(ActionEvent e) {
index++;
score++;
qScore.setText("",+score);
qText.setText(questions.get(index).getQuestions());
}
});
得分
JPanel scorePanel = new JPanel();
scorePanel.setLayout(new GridLayout(1,0));
JLabel label = new JLabel("Score:");
JTextField qScore = new JTextField();
qScore.setEditable(false);
任何想法,我究竟做錯了什麼?
如何發佈整個班級? – JamesB
你是否在按下yes按鈕時調試了代碼? – JamesB
您是否調試過actionPerformed方法? – JamesB