我正在努力学习Java,而且我有点玩这些东西,我遇到了关于文本字段监听器的问题。我做错了什么?
INTR。变量是具有正确答案的字符串。 scor的初始值为0.
问题在于,当我输入正确的答案时,我的结果仍为0。
final String raspunsul1 = rasp1.getText();
final String raspunsul2 = rasp2.getText();
final String raspunsul3 = rasp3.getText();
final String raspunsul4 = rasp4.getText();
JButton btnNewButton = new JButton("Trimite raspunsurile");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (raspunsul1.equals(intr1)){
scor = scor+25;
}
if (raspunsul2.equals(intr2)){
scor = scor+25;
}
if (raspunsul3.equals(intr3)){
scor = scor+25;
}
if (raspunsul4.equals(intr4)){
scor = scor+25;
}
JOptionPane.showMessageDialog(null,"Felicitari, ai obtinut " + scor + " puncte!");
}