![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2012
Posts: 1
Rep Power: 0
![]() |
Thread supposed to block keyevents
Hi There!
I wrote 2 class, the first is a canvas wich can listen to keyevents, the second is a thread wich sets a boolean variable to true, than 2 secs later to false. While the variable is true, one shouldnt supposed to change anything with a keypress, but one can. How can this be possible? Thanks. The listeners code. @Override
public void keyPressed(KeyEvent e) {
if(!keyPressed){
KeyboardBlocker kBB = new KeyboardBlocker(keyPressed);
kBB.start();
switch(e.getKeyCode()){
case KeyEvent.VK_UP:
rotUpperClockwise(upperRow, CLOCKWISE, 'Z');
break;
case KeyEvent.VK_DOWN:
rotUpperClockwise(upperRow, COUNTERCLOCKWISE, 'Z');
break;
case KeyEvent.VK_LEFT:
break;
case KeyEvent.VK_RIGHT:
break;
}
}
}the threads code: package szakdoga_real;
import java.util.logging.Level;
import java.util.logging.Logger;
public class KeyboardBlocker extends Thread{
private Boolean isKeyPressed;
public KeyboardBlocker(Boolean isKeyPressed) {
this.isKeyPressed = isKeyPressed;
}
@Override
public void run() {
isKeyPressed = true;
System.out.println(isKeyPressed);
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(KeyboardBlocker.class.getName()).log(Level.SEVERE, null, ex);
}
isKeyPressed = false;
System.out.println(isKeyPressed);
}
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why won't my Thread run? | PaCkEtPiRaTe | Java | 4 | Feb 20th, 2012 10:51 AM |
| Insert screenshot into PHP Nuke Block | kgqmbqrq | PHP | 0 | Aug 31st, 2011 5:25 AM |
| Thread waiting. | equinox | Java | 3 | Mar 7th, 2008 5:51 PM |
| Accessing another thread | BlazingWolf | C# | 2 | Apr 19th, 2006 4:19 PM |
| Passing array as argument to a thread | Symptom | C | 5 | Sep 30th, 2005 6:52 PM |