Main Menu

help!

Started by redred, May 18, 2006, 01:26:43 AM

Previous topic - Next topic

redred

What type of statement do you use to get a user input from what they typed? Please someone respond! Quick! Not much time left!

manumoi

Hello,

In JPCT apps, you have the KeyMapper class to help you. Here is an example of how you can use it (taken from i don't remember which example of Egon)


  private void poll(){
KeyState state = null;
do{
   state = keyMapper.poll();  // call to the poll method of the KeyMapper instance
   if (state!=KeyState.NONE){
keyAffected(state); // call to a keyAffected method that will describe the action to do once a key is pushed
   }
}
while (state != KeyState.NONE);
   }


And an example of the keyAffected related method

 private void keyAffected(KeyState state){
int code = state.getKeyCode();
boolean event = state.getState();
System.out.println(code);
switch(code){
case (KeyEvent.VK_ESCAPE):
   escape = event;
   break;
case (KeyEvent.VK_LEFT):
   left = event;
   break;
case (KeyEvent.VK_RIGHT):
   right = event;
   break;
case (KeyEvent.VK_UP):
   forward = event;
   break;
case (KeyEvent.VK_DOWN):
   backward=event;
   break;
}



Manu

EgonOlsen

Quote from: "redred"Not much time left!
To do what exactly?

Uija

The end is near! End everyone with a cool 3d app will be catched up by some aliens! :P

redred

i kind of wanted a quick reply...hehe?

redred

Quote from: "Uija"The end is near! End everyone with a cool 3d app will be catched up by some aliens! :P
strange people in the world, strange...lol

redred

Just incase this my post was read wrong, what i meant was
say i feel like making a calculator... this is where i want the user input to be used

number=([/i]somewaytogetwhatthepersontypedonthekeyboard)

If that changes things