Low-level transaction processing
To handle low-level transactions or perform a screen drawing, then we must use Canvas. It is also necessary to write mobile games.
Production, it provides graphics processing features that process keyboards, handwritten pens, and games. Because Canvas is inherited by Displayable, there is an Addcommadn () method, or one and Commmadn other attributes.
High-level transaction processing. Screen has the same characteristics in Canvas, but Screen allows developers to customize the listener, but Canvas does not
allow. Low-level transaction processing is generally divided into two, a keyboard, one is a handwritten pen. First let's take a look at the code for handling the keyboard / ** @AuThor you li * * Copyright (c) 2005 * / import javax.microedition.midlet. *; Import javax.microedition.lcdui. *;
Public class lleventmidlet extends MIDlet {
/ ** * * / private display; public lleventmidlet () {Display = display.getdisplay (this);}
/ * (Non-Javadoc) * @see javax.microedition.midlet.MIDlet # startApp () * / protected void startApp () throws MIDletStateChangeException {// TODO method of automatically generating stubs MyCanvas mc = new MyCanvas (); display.setCurrent (mc }
/ * (Non-javadoc) * @see javax.microedition.midlet.midlet # PauseApp () * / protected void pauseapp () {// TODO automatic generation method stub}
/ * (Non-Javadoc) * @see javax.microedition.midlet.MIDlet # destroyApp (boolean) * / protected void destroyApp (boolean arg0) throws MIDletStateChangeException {// TODO method of automatically generating stubs} class MyCanvas extends Canvas {String action = " "; Public void Paint (Graphics g) {// Clear screen G.SetColor (255, 255, 255); G.FillRect (0, 0, getWidth (), getHeight ()); g.setColor (0,0,0); / / Check if you support long button behavior if (haveRepeaTevent ()) {g.drawstring ("repeat", 10, 10, 0);} else {g.drawstring ("nonrepeat", 10, 10, 0);} g. DrawString (Action, 10, 20);} protected void keypressed (int keycode) {action = "kp:" (char) keycode; repaint ();} protected void keyreleased (int keycode {action = "KR: " (char) keycode; repaint ();} protected void keyrepeated (int keycode) {action =" KRE: " (char) keycode; repaint ();}}} This program will respond to the phone's keyboard behavior, then The key value corresponding to the click keyboard is displayed. From this program we can
To find out that when the CANVAS subclass is a picture that is being responding, simply click on the keyboard will trigger the keypressed () method. Loosen
Respond to the keyreleased () method. The method of supporting long button response is a keyrepeated () method (this method is not all machines
Both support, I don't have this response when I have used the 6110 6110. So you must be judged. And determine if support
The method of long button response is HASREPEATEVENTS ()). Key_Num0 ~~ key_num9, and key_star, key_pound is all machines
Also supported, and different other correspondence values depending on the device. In order to program cross-platform (huh, this is Java)
One of the biggest advantages), it is best to use these regular keyboard responses when you are developing. Of course, for the game design
Convenient, Canvas in MIDP define several GAME keyboard code: UP
, Down, Left, Right, Fire, Game_A, GAME_B, GAME_C, GAME_D. GetGameAction () and getKeycode ()
Two methods. To handle related behavior transformation. Handwriting pen control event processing, because there is no relevant device, there is no simulator, so there is no careful study, it is probably
There are a few more important things. Handwritten pen Click on the screen, trigger the PointerPressed () method, and passed into the click point to X, Y sitting on the screen
Sign. PointerReleased () responds when the handwritten pen leaves the screen. And Pointerdragged () is the movement of the handwritten pen on the screen.
The method of moving while generating the corresponding X, Y coordinates. If we need to cross-platform, we must use HaspoInterevents () to determine if the device supports the stylus. HaspoIntermotionevents () will be judged
Whether to support a handwritten pen to move to the screen to generate a PointerDragged () method.
Of course, there is still drawing processing and call processing. . . I really afraid that I can't accept so many concepts. . . Oh, ready
Rest awhile. These days have a good look at what you look at you a few days ago. War, know the new thing ^ _ ^
==============================================
Finally, I want to talk about it, because I saw a lot of friends I wrote this note, but no one responded. Let me feel depressed, I
Just hope that it can play a role of torch jade, I hope more brothers will learn together, improve, and help your younger brothers. . Ah
Ah. . . I hope everyone will leave. . ^ _ ^