Jak to, že mi nejde KeyListener?
package klavesnice;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class kl3 implements KeyListener {
static JLabel lab=new JLabel();
public static void main(String args[]) {
JFrame frame=new JFrame();
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lab.setText("normální stav");
frame.add(lab);
frame.setVisible(true);
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == 'a') {
lab.setText("po stisknutí");
}
}
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyChar() == 'a') {
lab.setText("po stisknutí");
}
}
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == 'a') {
lab.setText("po stisknutí");
}
}
}