I have an annoying problem, and I don’t seem to understand where in comes from. I have an application and a simple UI for it. The problem is that when I run the program buttons respond only to the second click. After they do what they have to do, buttons respond to the first click. I really don’t know what is the source of the problem. Here is some source code for binding jButton and actionlistener:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jButton1.addActionListener(new SolutionListener());
}
And here is actionlistener itself (if it helps):
private class ListListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
jTextArea1.setText(null);
if (jTextField2.getText().equals("")) {
jTextArea1.append("Input a value");
}
else {
for (int i = 2; i <= Integer.valueOf(jTextField2.getText().trim()); i++) {
if(isSquare(i) == true) {
continue;
}
else {
PE pe = new PE(i);
answer = pe.solve();
jTextArea1.append(i + "\t");
jTextArea1.append(answer[0].toString() + " ");
jTextArea1.append(answer[1].toString() + "\n");
}
}
}
}
}
I would really appreciate any help, thanks in advance!
If you try this:
One key click will print “outside Action” and the second will print “inside Action”.
You only need one ActionListener per JButton.