Keypressed() only working with 'cancel' key

Hi! Good Day! I am trying to make a game using the gameCanvas class, everything is fine except when I try to use the keyPressed() event so that I could evaluate what keys where pressed, unfortunately only the 'Cancel' key works on my program.
I am using J2ME wireless toolkit to build and run my program. Please help, Ive searched everywhere and all I see is sample code, but when I try to use keyPRessed() it still doesnt work the way its suppose to be. Thank you. Here's my code:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class WatchaWordCanvas extends GameCanvas implements Runnable {
  private boolean isPlay;   // Game Loop runs when isPlay is true
  private long delay;       // To give thread consistency
  private int currentX, currentY;  // To hold current position of the 'X'
  private int currentLocation;
  private boolean[] selectedBog = new boolean[16];
  private int staticX, staticY;
  private int bogposX, bogposY;
  private int width;        // To hold screen width
  private int height;       // To hold screen height
  private int[] bogArray = new int[16];
  private String[][] alphaMatrix = new String[4][4];
  private int ldelay, rdelay, udelay, ddelay;
  // Sprites to be used
  private Sprite playerSprite; 
  private Sprite backgroundSprite;
  private Sprite bogCubesSprite1;
  private Sprite[] bogCubesSprite = new Sprite[16];
  private Sprite bogBackGround;
  private Sprite bogTitleGround;
  private Sprite bogWordBar, bogMenuBar;
  private int dCtrA;
  // Layer Manager
  private LayerManager layerManager;
  // Constructor and initialization
  public WatchaWordCanvas() throws Exception {
    super(true);
    width = getWidth();   
    height = getHeight();   
    currentX = 0;
    currentY = 0;
    staticX = 2;
    staticY = (height / 2) - 60;
    delay = 20;
    ldelay = 0;
    rdelay = 0;
    udelay = 0;
    ddelay = 0;
    for (dCtrA=0; dCtrA<16; dCtrA++) {
      selectedBog[dCtrA] = false;
    // Load Images to Sprites
    Image playerImage = Image.createImage("/transparent.png");     
    playerSprite = new Sprite (playerImage,32,32);
    Image bogCubesImage = Image.createImage("/watcha-cubesfilled.png");
    bogCubesSprite1 = new Sprite(bogCubesImage,31,29);
    bogCubesSprite1.setFrame(0);
    Image bogBackImage = Image.createImage("/watcha-background2.png");
    bogBackGround = new Sprite(bogBackImage);
    Image bogTitleImage = Image.createImage("/watcha-title.png");
    bogTitleGround = new Sprite(bogTitleImage);
    Image bogWordImage = Image.createImage("/watcha-wordbar.png");
    bogWordBar = new Sprite(bogWordImage);
    Image bogMenuImage = Image.createImage("/watcha-menubar.png");
    bogMenuBar = new Sprite(bogMenuImage);
    for(dCtrA=0;dCtrA< bogCubesSprite.length;dCtrA++) {
      bogCubesSprite[dCtrA] = new Sprite(bogCubesImage,31,29);
      bogCubesSprite[dCtrA].setFrame(0);
    layerManager = new LayerManager();
    layerManager.append(bogTitleGround);
    layerManager.append(bogWordBar);
    layerManager.append(bogMenuBar);
    for(dCtrA=0;dCtrA< bogCubesSprite.length;dCtrA++) {
      layerManager.append(bogCubesSprite[dCtrA]);
    layerManager.append(bogBackGround);
    //Set the Positions of the Images
    bogTitleGround.setPosition(0,0); 
    bogWordBar.setPosition(2,150);
    bogMenuBar.setPosition(129,staticY - 2);
    bogCubesSprite[0].setPosition(staticX, staticY);
    bogCubesSprite[1].setPosition(staticX, staticY + 31);
    bogCubesSprite[2].setPosition(staticX, staticY + 62);
    bogCubesSprite[3].setPosition(staticX, staticY + 93);
    bogCubesSprite[4].setPosition(staticX + 31, staticY);
    bogCubesSprite[5].setPosition(staticX + 31, staticY + 31);
    bogCubesSprite[6].setPosition(staticX + 31, staticY + 62);
    bogCubesSprite[7].setPosition(staticX + 31, staticY + 93);
    bogCubesSprite[8].setPosition(staticX + 62, staticY);
    bogCubesSprite[9].setPosition(staticX + 62, staticY + 31);
    bogCubesSprite[10].setPosition(staticX + 62, staticY + 62);
    bogCubesSprite[11].setPosition(staticX + 62, staticY + 93);
    bogCubesSprite[12].setPosition(staticX + 93, staticY);
    bogCubesSprite[13].setPosition(staticX + 93, staticY + 31);
    bogCubesSprite[14].setPosition(staticX + 93, staticY + 62);
    bogCubesSprite[15].setPosition(staticX + 93, staticY + 93);
  // Automatically start thread for game loop
  public void start() {
    isPlay = true;
    Thread t = new Thread(this);
    t.start();
    SetCurrent();
  public void stop() { isPlay = false; }
  // Main Game Loop
  public void run() {
    Graphics g = getGraphics();
    while (isPlay == true) {
      input();
      drawScreen(g);
      try { Thread.sleep(delay); }
      catch (InterruptedException ie) {}
  public void input() {
    int keyStates = getKeyStates();
    //Left
    if ((keyStates & LEFT_PRESSED) !=0) {
      if (ldelay==0) {
        ldelay++;
        if (currentX > 0 ) { currentX--; }
        //SetCurrent();
    else {
      ldelay = 0;
    // Right
    if ((keyStates & RIGHT_PRESSED) !=0 ) {
      if (rdelay==0) {
        rdelay++;
        if (currentX < 3) { currentX++; }
        //SetCurrent();
    else {
      rdelay =0;
    // Up
    if ((keyStates & UP_PRESSED) != 0) {
      if (udelay==0) {
        udelay++;
        if (currentY > 0 )  { currentY--; }
        //SetCurrent();
    else {
      udelay = 0;
    // Down
    if ((keyStates & DOWN_PRESSED) !=0) {
      if (ddelay==0) {
        ddelay++;
        if (currentY < 3) { currentY++; }
        //SetCurrent();
    else {
      ddelay = 0;
  // Method to Display Graphics
  private void drawScreen(Graphics g) {
    //g.setColor(0x00C000);
    g.setColor(0xffffff);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(0x0000ff);  
    SetCurrent();
    // updating player sprite position
    //playerSprite.setPosition(currentX,currentY); 
    // display all layers
    //layerManager.paint(g,0,0);       
    //layerManager.setViewWindow(55,20,140,140);  
    layerManager.paint(g,0,0);
        bogCubesSprite[0].setPosition(staticX, staticY);
    flushGraphics();
  //Method to highlight cubes
  public void SetCurrent() {
    //some codes for my program
}Thanks in advance

Instead of the thread - Implement the keyPressed() and keyReleased() methods to keep track of events.
Regards,
Muthu Veerappan

Similar Messages

  • Has anyone figured out how to get speech recognition working with sticky keys enabled on mountain lion?

    I'm trying to use speech recognition to input text on my iMac running the latest mountain lion, 10.8.3.
    I have sticky keys enabled.
    When I try to start speaking by pressing the function key twice nothing happens. I can only get it to work if I disable sticky keys.
    The same problem occurs with all the other modifier keys as shortcut, they do not work with sticky keys.
    When I try to select a different shortcut, I am unable to select a two key combination, but am limited to one.
    If I select the F6 key, or any other single key, I am able to start speech recognition. However the second time that I press the key, it does not stop recognition and process my words. Instead, it restarts the recognition.
    Has anyone figured out how to get speech recognition working with sticky keys enabled?
    Or a way to get an individual key shortcut to start on the first press and process it on the second?
    Or a way to get key combinations to work, as specified by the help:
    Dictation On and Off
    To use Dictation, click On.
    When you’re ready to dictate text, place the insertion point where you want the dictated text to appear and press the Fn (function) key twice. When you see the lighted microphone icon and hear a beep, the microphone is ready for you to speak your text.
    Shortcut
    By default, you press the Fn (Function) key twice to start dictation. If you like, you can choose a different shortcut from the menu.
    To create a shortcut that’s not in the list, choose Customize, and then press the keys you want to use. You can press two or more keys to create your shortcut.

    I noticed with version 10.8.4 of OS X that I am now able to select F6 to activate, and the return key to complete the speech recognition. This is still different than the description of how these should function that's included in the help, but at least it's an improvement.

  • IPad is only works with changer , when I unplug it's not working

    My iPad 3 is only works with changer  when I unplug it's not working and not connecting to the PC even please some help?

    Hi,
    "But it didn't work it's just turning them to black gray scale colors not what i was thinking about."
    If you want it to be colored, you'll need to create a color-palette for the 8bppIndexed bitmaps. The keyword for this process is "Color-Quantization".
    The whole yellow-green pie you get is from the wrong format. If you convert the 32bpp bitmaps to 24 bpp bitmaps, you loose the alpha channel ("transparency"). You can manually set one color to "transparent" with the mMakeTransparent-method
    of the Bitmap class, or simply use gif-images (they are 8bpp with a transparent "key"-color)
    Regards,
      Thorsten

  • I have a touchscreen laptop running Windows 8.1. Is it possible to use the touchscreen with Firefox? I've installed Firefox but it only works with the mouse etc

    have a touchscreen laptop running Windows 8.1. Is it possible to use the touchscreen with Firefox? I've installed Firefox but it only works with the mouse etc

    Hello Sirving575, sorry but the metro version of firefox has been cancelled, see : https://blog.mozilla.org/futurereleases/2014/03/14/metro/
    thank you

  • Does Mighty Mouse only work with desktop Macs??

    I just bought an Apple Wireless Mighty Mouse, assuming it'd work with my new Leopard OS X Macbook. I followed the instructions on the Mighty Mouse booklet...but no installation start-up window ever appeared. I'm a beginner with Apple, so I figure I've done something wrong....does the Mighty Mouse only work with desktop Macs and not MacBooks?
    Please help if you can.

    Ah! sorry, my mistake! "wireless" was the key word. And yes, prior to my new mighty mouse, I also used the wireless one. And you need to do the following:
    1) Turn bluetooth ON (either from finder icon (you can have it placed on your finder bar by tick box in sytem preferences/bluetooth.
    2) Then, you need to "pair" your mouse via bluetooth setup assistant.
    3) once "paired" off you go.

  • F9 and F10 only work with fn pressed

    My F9 and F10 keys only work with fn pressed, whereas all the other top line function keys will work alone.
    Is this normal?
    Mike

    Well for the backlight function I don't believe it can be changed. For Expose´however you need simply to go into System Preferences. There you'll see the control for Dashboard & Expose´. From there you can change the function keys for Expose´ if you want.
    Jrsy

  • Media keys (volume, brightness, mute ect.) only work as F-keys.  How do i fix them?

    I have a macbook air 13 newer model (mid 2013) and after installing Maverick OS X version 10.9.2, my function keys only work as function keys (F1, F2, F3...) but do not do any of the media fuctions (play, forward, back, volume, mute, brightness...).  I have tried going to keyboard setting and making sure the option to use as standard function keys is not set.  With or with out the check mark they still only work as F keys, even when I press and hold fn key or not.  I have tried doing a wipe of hard drive and doing a new install of maverick twice but that did not help.  I have tried rebooting into safe mode and then rebooting back but still no luck.  I don't belive this is a hardware problem since the keys work as F-keys.  Maybe it is missing some driver or something but I have no idea what to do.  My keyboard is set to US on the imput source setting.  All updates seem to be up to date.  What else can I do to fix this issue.

    Dudadew wrote:
    I have tried rebooting into safe mode and then rebooting back but still no luck.
    When you booted into Safe Mode did the function keys operate properly? If so then the problem is somwhere in your account or with some kernel extension you have loading. (Only Apple's most vital kernel extensions are loaded in Safe Mode.) If the function keys operate properly in Safe mode let us know.
    You referred to reinstalling Mavericks. If you used a backup to migrate your applications and data afterwards it is possible you migrated the problem right back onto the computer. I have had Mavericks installed on a number of computers ranging from a 2007 iMac to a 2013 Mac mini (and some notebooks) without the problem you describe so I'm pretty confident that it isn't Mavericks itself but rather something else is involved in the equation.

  • I bought this iPhone from Apple Retail Store for the full amount, but  it does not work with my SIM card only works with AT&T

    Hello,
    I have an iPhone 4S 32Gb White AT&T, product part No. MC921LL/A, Serial No. C39GMLPWDTDC
    I bought this iPhone from Apple Retail Store (from Fifth Avenue, NY) for the full amount. Now it does not work with my SIM card only works with AT&T. I restored the phone several times, but I have not received "Congratulations your iPhone has been unlocked". Please activate my iPhone to work with different SIM cards
    Thanks,
    Best Wishes

    When did you buy it?
    Apple did not begin selling an unlocked version of the iPhone 4S in the US until 11/11/11. I believe it went on sale only through the online store at that time. I'm not sure if it's available at retail yet.
    What you purchased was a phone without a contract commitment. It is still locked to AT&T. AT&T will NOT unlock iPhones for any reason.  Return it and get your money back, then use that to purchase an unlocked phone.

  • Can't sign in using any 3rd party email client with my iCloud account on any Mac. Tried every settings, My iCloud only works with Mail.app

    Can't sign in using any 3rd party email client with my iCloud account on any Mac or any other Mac. My iCloud will only work with Mail.app. All the clients I tried work perfectly well as long as I sign in with somebody else's iCloud account. But mine won't work no matter the client (Postbox, Unibox, Airmail...) and no matter the computer.
    I can access my account on iCloud.com, but I can't use email clients without getting error messages prompting me to check my password or login.
    I was able to use those clients in the past but a couple of months ago I got logged out of Airmail and the issue started just like that!
    I tried every possible mail server settings including the following:
    IMAP information for the incoming mail server
    Server name: imap.mail.me.com
    SSL Required: Yes
    If you receive errors when using SSL, try using TLS instead.
    Port: 993
    Username: The name part of your iCloud email address (for example, emilyparker, not [email protected])
    Password: Your iCloud password
    SMTP information for the outgoing mail server
    Server name: smtp.mail.me.com
    SSL Required: Yes
    If you receive errors when using SSL, try using TLS instead.
    Port: 587
    SMTP Authentication Required: Yes
    Username: Your full iCloud email address (for example, [email protected], not emilyparker)
    Password: Your iCloud password

    Those are the correct settings, and they work with any email client that supports Imap.
    Try again.

  • Ipod Classic 160 6th g. doesn't sync w/Imac g5 non intel OS 10.4.11. This is a replacement for same ipod which was stolen recently. That pod worked fine with Itunes 9! Now this pod says it only works with Itunes 10.7. ***!!!! Why has Apple screwed up?

    My ipod classic 160 6th gen. was recently stolen. It had 3000 tunes on it and it synced perfectly with Itunes 9 on my Imac G5 non intel OS 10.4.11. So I recently bought same model and guess what, it doesn't sync at all. Now message says it only works with Itunes 10.7 and up. I certainly cant afford to buy a new intel based Mac and I really dont need a new pc. It feels like Apple has dropped the ball on its long time users and tough luck to you and all the $$$$$$$ spent on downloading songs and buying ipods over the years! I AM SO ANGRY THAT I CANNOT BRING MY MUSIC WITH ME ANYMORE. I dont know if there is any solution to this except being extorted to upgrade to new tech! I have been trying to get answers to this issue but nothing seems to work. Any help would be greatly appreciated. I am not a tech genius so extremely techy solutions will be in vane.

    one more detail, after a restore, when I attempt to reload music to the ipod, if I try and move, say, 20 files, the transfer seems to work as it should but then stalls on the last file.  Eventually, the status will change to "Updates Files on (my ipod)" a and suggests the iPod is syncing  even though I have the auto sync feature turned off.
    This process eventually works itself out, and seems to take longer relative to the number of files I attempt to transfer.   Once done, howver, if I try and eject and dismount the iPod, iTunes stalls with the spinning pinwheel and I am warned that the iPod is syncing again with the spinning candy cane status bar.     Eventually thisd works itself out and the iPod dismounts from iTunes and the desktop and eventually the iPod is free to disconnect.
    Then if I try and play the music I just transfered, the iPod says there is no music loaded.
    Ideas?

  • I am using Windows 7 64-bit on a partitioned hard drive on a MacAir.  The trackpad will only work with a click.  How do I get the full function of tap and scroll?

    I am using Windows 7, 64-bit on a partitioned hard drive on a  2012 MacAir.  The trackpad only works with clicking.  How do I get the full function of tap and scroll? (I have this on a 2011 Mac Pro with 32 bit Windows 7 and it works properly.)

    Windows Control Panel>Boot Camp Control Panel>Trackpad.

  • Boot Camp won't make a Windows XP driver disc, OS X disc only works with Win7

    First time Mac user. Just got a new Macbook Pro.
    I have successfully installed Windows XP on the Mac using Boot Camp. But I need the driver disc. The right mouse button doesn't even work and Windows is impossible to navigate without that. The disc eject button does not work, one has to eject a disc using laborious menus. Very frustrating.
    When I run Boot Camp it only has the option to make a Windows 7 driver disc. I don't see any way to make a driver disc for Windows XP.
    Everywhere I have searched on the Net the information says to put the OS X Leopard disc in the drive when WinXP is running and it will automatically install drivers. When I try that a window comes up saying it only works with Windows 7.
    This web site shows screen shots of a Beta version of Boot Camp that makes Windows XP drivers discs.
    http://www.askdavetaylor.com/how_do_i_install_windows_xp_on_my_mac_using_boot_ca mp_1.html
    How can I make a Windows XP driver disc?
    I really hope Apple didn't discontinue/eliminate the option to make a Windows XP driver disc altogether, forcing everyone to use Windows 7 only...
    Is there a way to install an older version of Boot Camp over the latest version I'm running? Where would I find it?
    Macbook Pro
    OS X 10.6.7
    Boot Camp 3.0.4
    Thank you for your time in helping me on this.

    The retail OS X 10.6.3 DVDs unlike your OEM DVD does have a complete set of drivers for $29 w/o having to deal with questionable bitorrent.
    Microsoft EOL'd XP and Vista SP1.
    Your Mac has Intel Thunderbolt and you don't see Apple doing backward compatibility. You can't run 10.5 on new Mac. So yes it comes with those limitations, but XP is also 20x more vulnerable, IE9 is more secure and XP has not kept up with the latest hardware, besides which I don't see a place or need for a 32-bit OS, any platform today.

  • When trying to install an extension for InDesign CC 2014 I get an error message saying that the extension only works with version 7.0 or greater. My version is 10.0.0.7 x64 Build I was using this extension fine with InDesign CC

    When trying to install an extension for InDesign CC 2014 I get an error message saying that the extension only works with version 7.0 or greater. My version is 10.0.0.7 x64 Build I was using this extension fine with InDesign CCError message with InDesign CC 2014

    Used the 64bit version before CC 2014 as well so don't think that's the issue. Here is the text in the .mxi file if I have missed something:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <macromedia-extension id="PrintUI Tools" name="PrintUI Tools" requires-restart="true" version="3.0.0">
      <author name="PrintUI.com"/>
      <description/>
      <license-agreement/>
      <products>
        <product maxversion="" name="InDesign" primary="true" version="7.0"/>
      </products>
      <files>
        <file destination="" file-type="CSXS" products="" source="PrintUIManagement.zxp"/>
      </files>
      <update url="http://printui.com/public/downloads/updates/printui_tools_update.xml"/>
    </macromedia-extension>

  • I purchased Adobe photoshop elements II and Adobe premiere elements II. They are both on one disc. My computer crasded and I had to reload Windows. I only have one serial number and it only works with photoshop II. The same serial number will not work for

    I purchased Adobe photoshop elements II and Adobe premiere elements II. They are both on one disc. My computer crasded and I had to reload Windows. I only have one serial number and it only works with photoshop II. The same serial number will not work for Premiere. I dont have any other serial numbers. What do I do???

    Static_Unit
    I am getting a bit concerned about what is happening in your situation. Yesterday you posted your question in at least two different forums, one of them being here in the Premiere Elements Forum.
    Don't Have Serial Number for Premiere, Only Photoshop?
    Wherever you posted, the reply was to contact Adobe via its Adobe Chat. It is the only one who can sort out this matter for you.
    In the thread cited above I offered to help you with the difficulties that you were having visualizing the Adobe Chat in its web page. I was waiting for your follow up on that in the above thread. Instead, I find your same question in a new Adobe Premiere Elements Forum thread this afternoon with no refer the prior threads or prior recommendations given you.
    I will also mention again...when you buy the Photoshop Elements and Premiere Elements bundled in one packaging and with installation files for each on the same installation disc, each program has its own serial number. The Photoshop Elements serial number does not work for Premiere Elements and vice versa. The serial numbers are on labels on a box which houses the installation disc envelope(s). So, if you purchased both programs and found the Photoshop Elements serial number, then the Premiere Elements serial number should be in a label right underneath the label with the serial number for Photoshop Elements. I recall writing this in your yesterday's thread on this matter.
    The moderator will no doubt be along shortly to close or delete this thread. So, just in case, please bookmark your yesterday's thread cited above so that we can continue this communication which is trying to help you.
    Thanks.
    ATR

  • I had an iphone 4s and it worked nice with facetime and imessage using my phone number but  it was stolen on December so I buy a new iphone 4s using the same cellphone number  but now imessage and facetime does not work with my number, it only works with

    I had an iphone 4s and it worked nice with facetime and imessage using my phone number but  it was stolen on December so I buy a new iphone 4s using the same cellphone number  but now imessage and facetime does not work with my number, it only works with my apple ID.   Please Help me I speak Spanish so  if my English is not ok  I´m sorry about it.
    Do you think that apple has to   reset in their database of the old serial number attached with my phone number and that’s why I can´t activate imessage and facetime with my number in the new iphone 4s?? 

    I understand all of this Meg; that is why I bought an Iphone; but never expected my phone not even give a at least a 24 or even 12 hours....I work 12 hour shifts and also would expect to have to charge each night but not twice a day or more.  I am not always somewhere I can charge my phone.
    Your points are true; however it doesn't help me......

Maybe you are looking for

  • Paragon installer

    I try to install the 'Paragon - NTFS for Mac' driver for my mac pro, but it exit automatically when I install. Just wanna know what's wrong with my mac, as I can istall this driver to my other mac air (using system 10.8.5). Thanks, Nic

  • Importing Bank Master Data in AP

    Hi, We have a requiremnet at client to import Bank Master data. As we don't have a standard interface to do that in AP,I would appreciate if anyone can let me know information on this.Any of you have done this before please share your experiences on

  • GMapsTaskFlow example : NoClassDefFoundError MapTag

    hi Using the example application in GoogleMapsTF.zip, that Edwin Biemond provided with his blog post "Google Maps Task Flow", I get this exception: WARNING: Error trying to include:viewId:/googlemaps-flow-definition/maps uri:/maps.jsff javax.servlet.

  • Join between two nested tables question

    Hi. I have two nested tables with a join statement drawing info from both. The query looks like this: select to_char(N.LASTLOGONDATE, 'YYYY'), count(n.u_name), A.ACCOUNTDISABLED from coclastlogon, TABLE(COCLASTLOGON.RLLS) N , userpwaudit, TABLE(USERP

  • Free Characteristic, range value, filtering query for iveiw in WAD

    Using the web application designer I am adding a query (BW 3.5) to a sales portal (EP 6.0) of all projected wins (custom characteristic on opp header).  Sales has requested I provide in by mth and by qtr.  I created value ranges in my projected win c