I have the following problem. I have a small form with a button (we’re talking about JAVA here), which sends the data in the form trough a socket-connection with the server. Now, when i press the button, it’s making this single connection, but in the meanwhile, the button remains ‘pressed’, if you get me. After the action, activated by the actionlistener, has been completed (made connection, sent data, closed connection) the button get released.
Now my question is, is there a simple fix for that, and if so (or not), how can i fix this?
Thanks in advance.
submit.addActionListener(this);
And this is the part, but i hope that was made clear in the text.
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == submit) {
boodschap = testtext.getText();
// System.out.println(boodschap);
try {
try {
UserConnection connect = new UserConnection(boodschap);
} catch (SQLException ex) {
Logger.getLogger(UserAction.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(UserAction.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
(oh, this code works like a charm. There’s nothing wrong with the code, it’s just displayed to give you an indication of what i mean.)
The problem is that you are doing a long-running operation on the UI thread. If you put your code into a SwingWorker or even into a Runnable and run it in a new thread it should resolve your problem