2 Replies Latest reply: Jan 27, 2010 8:50 AM by 843853 RSS

    Moto ROKR E6 virtual keyboard for typing in a MIDLET

    843853
      Hello,



      I in the process of coming up with small game using GameBuilder available on netbeans.I was able to create a small animation ( setup a scene, sprites and some layers ) , what I could not figure out is how to get the keyboard,so that i can type some letters on screen during a game.


      Also, On the simulator(i guess it is the SUN wireless kit) how do we switch to alphabet mode ?


      Please suggest .


      Thanks,

      Edited by: varun_tayur on Jan 26, 2010 3:11 PM
        • 1. Re: Moto ROKR E6 virtual keyboard for typing in a MIDLET
          843853
          You can do a KeyListener to get your input from the keyboard, check the API and tutorial for the specifics.
          • 2. Re: Moto ROKR E6 virtual keyboard for typing in a MIDLET
            843853
            public class X extends GameCanvas implements Runnable
            {
             String eventType = "- Press any!";
                int keyCode;
            
                public void keyPressed(int keyCode)
                {
                    eventType = "pressed";
                    this.keyCode = keyCode;
                    repaint();
                }
            
                public void keyReleased(int keyCode)
                {
                    eventType = "released";
                    this.keyCode = keyCode;
                    repaint();
                }
            
                public void keyRepeated(int keyCode)
                {
                    eventType = "repeated";
                    this.keyCode = keyCode;
                    repaint();
                }
            
                public int write(Graphics g, int y, String s)
                {
                    g.drawString(s, 0, y, Graphics.LEFT | Graphics.TOP);
                    return y + g.getFont().getHeight();
                }
            
                public void paint(Graphics g)
                {
                    g.setGrayScale(255);
                    g.fillRect(0, 0, getWidth(), getHeight());
            
                    g.setGrayScale(0);
            
                    int y = 0;
                    y = write(g, y, "Key " + eventType);
                    if (keyCode == 0)
                    {
                        return;
                    }
            
                    y = write(g, y, "Char/Code: " + ((keyCode < 0) ? "N/A" : "" + (char) keyCode) + "/" + keyCode);
                    y = write(g, y, "Name: " + getKeyName(keyCode));
                    String gameAction;
                    switch (getGameAction(keyCode))
                    {
                        case LEFT:
                            gameAction = "LEFT";
                            break;
                        case RIGHT:
                            gameAction = "RIGHT";
                            break;
                        case UP:
                            gameAction = "UP";
                            break;
                        case DOWN:
                            gameAction = "DOWN";
                            break;
                        case FIRE:
                            gameAction = "FIRE";
                            break;
                        case GAME_A:
                            gameAction = "GAME_A";
                            break;
                        case GAME_B:
                            gameAction = "GAME_B";
                            break;
                        case GAME_C:
                            gameAction = "GAME_C";
                            break;
                        case GAME_D:
                            gameAction = "GAME_D";
                            break;
                        default:
                            gameAction = "N/A";
                    }
                    write(g, y, "Action: " + gameAction);
                }
            }
            The above code works perfectly fine, except that I do not see any facility to capture the alphabets from a mobile phone simulator (or the phone itself).I wanted to know how I can change the mode to alphabets, as we do while we compose a SMS ( alphabet mode, numeric input mode etc. ) .
            Hope you understand what I am looking at .

            Thanks

            Edited by: varun_tayur on Jan 27, 2010 8:19 PM - Corrected Typo's