I have a JLabel which has a string that has an integer, which starts at 0. I want it so that way, every time a key (like "w") is pressed, the integer goes up by 1. I have searched the web far and wide, but I have returned nothing (maybe because of my wording). Here's the code:
public void keyTyped(KeyEvent e) {
//keyTyped = Invoked when a key is typed. Uses KeyChar, char output
switch(e.getKeyChar()) {
case 'a': label.setLocation(label.getX()-10, label.getY());
for(int coins=0; coins<1;coins++) {
coins = coins + 1;
}
break;
case 'w': label.setLocation(label.getX(), label.getY()-10);
for(int coins=0; coins<1;coins++) {
coins = coins + 1;
}
break;
case 's': label.setLocation(label.getX(), label.getY()+10);
for(int coins=0; coins<1;coins++) {
coins = coins + 1;
}
break;
case 'd': label.setLocation(label.getX()+10, label.getY());
for(int coins=0; coins<1;coins++) {
coins = coins + 1;
}
break;
}
}
Maybe it is what I wrote in the code and it won't change? I didn't see similar questions like mine.