Notes on the use of mobile keyboard in J2ME development

Source: Internet
Author: User

In the development of the J2ME program, often need to accept the user input, and all of these input is through the mobile phone keyboard, the following describes the use of time to pay attention to the problem.

In advanced user interface development, you can only use the function keys to control command buttons, these are fixed patterns, such as mobile phone display two command, corresponding to the screen of the left and right two command, do not need the user to process key values, so there is no transplant problem, is common on all mobile phones.

However, in the low-level user interface development, you can directly access the phone's key value (KeyCode), because the key of the different mobile phone keys, there is a difference, so there is a transplant problem.

In the mobile phone keyboard, can be simply divided into functional key area and the number of key areas, function key refers to the mobile phone on the soft key, the middle of the navigation key and answer the phone and hanging machine keys, and so on, the number key area refers to the mobile phone keypad on the 0-9 number keys as well as The number of function keys and key values, different mobile phones, and the number of keys in the area of the number of keys, as well as key values are the same.

So in the game in order to make the program general, generally do not use the key value directly to judge, but the game action (gameaction) to distinguish: the implementation of the code is as follows:

//将keyCode转换为游戏动作
int action = getGameAction(keyCode);

The corresponding relationship between KeyCode and game action is as follows:

canvas.up--number key 2 and up navigation key

canvas.down--number keys 8 and down navigation keys

canvas.left--number keys 4 and left navigation keys

canvas.right--number key 6 and right navigation key

canvas.fire--number key 5 and OK navigation keys

Game_a, Game_b, Game_c, game_d, respectively, correspond to 1, 3, 7, 9, or 7, 9, *, and #键 on the keyboard.

After the transformation above, the code implementation is not related to the key value on the phone's keyboard.

In addition, if it is the Nokia series of mobile phones, you can also use the Com.nokia.mid.ui.FullCanvas class inside the SOFTKEY1, SOFTKEY2 to control the Nokia series of mobile phones on the left and right two soft keys, so that the two soft key processing general.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.