KeyEvent inside Eclipse/WindowBuilder doesn't work [message #995601] |
Sun, 30 December 2012 16:24  |
Eclipse User |
|
|
|
I'm developing a GUI using windowBuilder and Eclipse. I try to use a keyEvent that it shows the key that you push in a window. When I run the program the console shows "Need to specify an input file!".
When I push "Quickly test/preview...." button inside Eclipse/WindowBuilder I can see the window but it doesn't work (if I push a button it doesn't show anything). The code is this one (it's a example I found in a book so I don't know what's the problem):
public class KeyChecker extends JFrame {
JLabel keyLabel = new JLabel("Presiona cualquier tecla");
public KeyChecker() {
super("Presiona cualquier tecla");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
KeyMonitor monitor = new KeyMonitor(this);
getContentPane().setFocusable(true);
getContentPane().addKeyListener(monitor);
getContentPane().add(keyLabel);
setVisible(true);
}
public static void main(String[] args){
new KeyChecker();
}
}
And the KeyMonitor code:
class KeyMonitor extends KeyAdapter{
KeyChecker display;
KeyMonitor(KeyChecker display){
this.display = display;
}
public void keyTyped(KeyEvent evt){
display.keyLabel.setText(" " + evt.getKeyChar());
display.repaint();
}
}
I've run the code in other computers and it works so... Can you tell me a posible solution? Where is the problem?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04352 seconds