Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

jwindow exit when keypress

  Asked By: Chisisi    Date: Apr 18    Category: Java    Views: 1242
  

like i said in my previous messages,i have this application that must
act like a screensaver,at first i used jframe and include
mouselistener and keylistener.when user click the mouse or press a
key the application will exit.now i changed my application to
jwindow,the mouselistener work fine,but when i press any key,the
application will not exit.can anyone help me with this?thanks in
advance...
these are part of my codes...
i have include addKeyListener(this);

public void keyPressed(KeyEvent e)
{

char keyChar = e.getKeyChar();

//if((x = e.getKeyChar()) >= '0' && x <= '9')
if ( ((keyChar > '0') && (keyChar < '9')) || // 0-9
(keyChar == '.') || (keyChar == '-') || // . -
(keyChar == 8 ) || (keyChar == 127) || // backspace or delete
(keyChar == 106 ) || (keyChar == 111) ||// *, /
(keyChar == 144 ) || (keyChar == 107) ||// numlock, +
(keyChar == 61 ) || (keyChar == 92) || // =, \
(keyChar == 155 ) || (keyChar == 36) || // insert, home
(keyChar == 33 ) || (keyChar == 34) || //pageup, pagedown
(keyChar == 35 ) || (keyChar == 38) || // end, arrow up
(keyChar == 37 ) || (keyChar == 40) || // arrow left, arrow down
(keyChar == 39 ) || (keyChar == 192) || //arrow right, ~
(keyChar == 20 ) || (keyChar == 16) || //capslock, shift
(keyChar == 17 ) || (keyChar == 18) || //ctrl, alt
(keyChar == 32 ) || (keyChar == 47) || //space, /
(keyChar == 44 ) || (keyChar == 59) || //,,;
(keyChar == 222 ) || (keyChar == 93) || //', ]
(keyChar == 91 ) || (keyChar == 80) || // [, p
(keyChar == 79 ) || (keyChar == 73) || // o, i
(keyChar == 85 ) || (keyChar == 89) || //u, y
(keyChar == 84 ) || (keyChar == 82) || //t, r
(keyChar == 69 ) || (keyChar == 87) || //e, w
(keyChar == 81 ) || (keyChar == 65) || //q, a
(keyChar == 83 ) || (keyChar == 68) || //s, d
(keyChar == 70 ) || (keyChar == 71) || //f, g
(keyChar == 72 ) || (keyChar == 74) || //h, j
(keyChar == 75 ) || (keyChar == 76) || //k, l
(keyChar == 90 ) || (keyChar == 88) || //z, x
(keyChar == 67 ) || (keyChar == 86) || //c, v
(keyChar == 66 ) || (keyChar == 78) || //b, n
(keyChar == 77 )) //m
{
e.consume();
System.exit(0);
}
}

Share: 



Tagged: