How to call Exit Command when I press Key # in Lwu

2019-03-03 15:34发布

Can I assign the Exit Command to the # key in an Lwuit Application? When I press the key #, the Exit command should be called automatically and exit the application.

1条回答
闹够了就滚
2楼-- · 2019-03-03 16:13

You should listen for a KeyPress or keyReleased event on the form with the keycode for # and exitApplication when the # key is pressed.

protected void keyPressed(int key)
{
    System.out.println("Key Pressed");

    if(key==52) //change 52 to match keyCode for # key 
    {
      Display.getInstance().exitApplication();
    }
}
查看更多
登录 后发表回答