Friday, November 29, 2013

.setVisible() not working



Java Code:



public void mouseClicked(MouseEvent e) {
if (textAddedPlayerName.getText().equals("")) {
lblERROR.setVisible(true);
long start = System.currentTimeMillis();
long current = System.currentTimeMillis();
while (current - start < 2000) {
current = System.currentTimeMillis();
}
lblERROR.setVisible(false);
}else {
String temp = textAddedPlayerName.getText();
list.add(temp);
}
}
});

Whenever I run this code my lblERROR label does not seem to become visible, the timer just starts and runs for the 2 seconds. I read online about repainting but that also did not help.

lblERROR was added onto a panel if that has something to do with it.

Also is their a better way to make a timer, as this while loop causes that no other operations can be done by the user, ex he cant type anything in textAddedPlayerName for the 2 seconds.


PS: I'm just starting to learn Swing , so please be gentle.



No comments:

Post a Comment