I'm trying to increment/decrement a user score as appropriate inside a text field on a (very) basic GUI. How, I only succeed in decrementing even though there is proof my conditional works correctly. Here is the pertinent code; I can supply more as needed.
//buttons: array of JButtons
//scoretxt: JTextField holding the score
//name- object name stored as string in separate string array
//check- odd numbers pass incorrect, evens pass correct
//safe: JTextArea for output
for (int i = 0; i < 18; i++) {
final String myname = "" + (buttons[i].getClientProperty("name"));
final String myval = "" + (buttons[i].getClientProperty("value"));
final String corr = "" + (buttons[i].getClientProperty("check"));
buttons[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
safe.append(myname + " " + ("" + myval));
if (corr == "correct") {
safe.append(" " + corr + "\n");
scoretxt.setText("" + ((Integer.parseInt(scoretxt.
getText())) + 1));
} else {
safe.append(" " + corr + "\n");
scoretxt.setText("" + ((Integer.parseInt(scoretxt.
getText())) - 1));
}
}
});
mygui.add(buttons[i]);
}
I have tried various approaches but I always rely on scoretxt.getText()
to pass a value. Any and all help is appreciated, thanks.