Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 10th, 2012, 3:31 PM   #1
fecoooo
Newbie
 
Join Date: Mar 2012
Posts: 1
Rep Power: 0 fecoooo is on a distinguished road
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);  
    }  
      
}
fecoooo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why won't my Thread run? PaCkEtPiRaTe Java 4 Feb 20th, 2012 11:51 AM
Insert screenshot into PHP Nuke Block kgqmbqrq PHP 0 Aug 31st, 2011 6:25 AM
Thread waiting. equinox Java 3 Mar 7th, 2008 6:51 PM
Accessing another thread BlazingWolf C# 2 Apr 19th, 2006 5:19 PM
Passing array as argument to a thread Symptom C 5 Sep 30th, 2005 7:52 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC