Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.51 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. I ported my midlet to Blackberry and I can't assign a listener to the ESCAPE key
  2. import net.rim.device.api.system.KeyListener;
  3. import net.rim.device.api.ui.Keypad;
  4.  
  5. public class PhraZApp extends javax.microedition.midlet.MIDlet implements ActionListener{
  6.  
  7. public PhraZApp {
  8.  addKeyListener (new KeyPadListener());
  9. }
  10.  
  11.  
  12.  protected void keyPressed(int key) {
  13.     System.out.println(key);
  14. }
  15.  
  16. public void actionPerformed(ActionEvent evt) {
  17.     System.out.println(evt.getKeyEvent());
  18. }
  19.  
  20.  public final class KeyPadListener implements KeyListener {
  21.  
  22.     public boolean keyChar(char key, int status, int time) {
  23.  
  24.         return false;
  25.     }
  26.  
  27.     public boolean keyDown(int keycode, int time) {
  28.         if (Keypad.KEY_ESCAPE == Keypad.key(keycode)) {
  29.                   System.out.println("key: " + keycode);
  30.         return true;
  31.     }
  32.             //let the system to pass the event to another listener.
  33.     return false;
  34.     }
  35.  
  36.     public boolean keyUp(int keycode, int time) {
  37.         throw new UnsupportedOperationException("Not supported yet.");
  38.     }
  39.  
  40.     public boolean keyRepeat(int keycode, int time) {
  41.         throw new UnsupportedOperationException("Not supported yet.");
  42.     }
  43.  
  44.     public boolean keyStatus(int keycode, int time) {
  45.         throw new UnsupportedOperationException("Not supported yet.");
  46.     }
  47. }
  48.        
  49. Command backCommand = new Command("",Keypad.KEY_ESCAPE);
  50. form.setBackCommand(backCommand);
  51.        
  52. public void actionPerformed(ActionEvent evt) {
  53.  
  54.     if (evt.getCommand().getId() ==Keypad.KEY_ESCAPE){
  55.         //execution code  
  56.     }