Learning notes for j2-based learning platform (6)

Source: Internet
Author: User

Low-level Transaction Processing

To process low-level transactions or screen drawing, we must use canvas. Canvas is also required to write mobile games.

It provides the processing keyboard, pen, and graphic processing functions of the game.
Because canvas is inherited by displayable, it has the addcommadn () method and can also be associated with other commadn attributes.

Into advanced transaction processing. Screen has the same features as canvas, but screen allows developers to customize listeners, But Canvas does not

Yes.
There are two types of low-level Transaction Processing: one is the keyboard and the other is the handwriting.
First, let's look at the code for processing 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 automatically generates method stubs
Mycanvas MC = new mycanvas ();
Display. setcurrent (MC );
}

/* (Non-javadoc)
* @ See javax. microedition. MIDlet. MIDlet # pauseapp ()
*/
Protected void pauseapp (){
// Todo automatically generates method stubs
}

/* (Non-javadoc)
* @ See javax. microedition. MIDlet. MIDlet # destroyapp (Boolean)
*/
Protected void destroyapp (Boolean arg0) throws midletstatechangeexception {
// Todo automatically generates method stubs
}
Class mycanvas extends canvas {
String action = "";
Public void paint (Graphics g ){
// Clear the screen
G. setcolor (255,255,255 );
G. fillrect (0, 0, getwidth (), getheight ());
G. setcolor (0, 0, 0 );
// Check whether long button actions are supported
If (hasrepeatevents ()){
G. drawstring ("repeat", 10, 10, 0 );
} Else {
G. drawstring ("nonrepeat", 10, 10, 0 );
}
G. drawstring (Action, 10, 20, 0 );
}
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 keyboard behavior of the mobile phone, and then display the key value corresponding to the clicked keyboard. From this program, we can

The keypressed () method is triggered when you click the keyboard when the canvas subclass becomes a response screen. When released

Response keyreleased () method. The keyrepeated () method is used to support long-key response (this method is not all machines ).

All supported. For example, 6110 of N records are not generated when I used them before. Therefore, you must make a judgment. Determine whether or not to support

Hasrepeatevents () is the method for Long-key response ()). Key_num0 ~~ Key_num9 and key_star and key_pound are all machines.

Constants are supported, and there will be different other corresponding values depending on the device. In order for the program to be cross-platform (haha, This is a Java

One of the biggest advantages). It is best to use only these regular keyboards for response in less special cases during development. Of course, designed for games

Convenience. In MIDP, canvas defines several game keyboard codes: Up

, Down, left, right, fire, game_a, game_ B, game_c, game_d. Getgameaction () and getkeycode () are also defined ()

Two methods. To process the relevant behavior conversion.

Because I have no relevant device or simulator, I have not studied it carefully.

Next several important things. Click the screen with a pen, trigger the pointerpressed () method, and input the click point to sit on X and Y on the screen.

. Pointerreleased () responds when the pen leaves the screen. Pointerdragged () is the movement of the pen on the screen.

The dynamic response method generates the corresponding X and Y coordinates. If our development program needs to be cross-platform, support in the response pen Service

Haspointerevents () must be used to determine whether the device supports a pen. Haspointermotionevents () Determines

Whether or not the pointerdragged () method can be generated when a pen moves on the screen.

Of course, there are also plot processing and call processing... I am afraid that I cannot accept so many concepts... Prepare

Take a break. Let's take a look at what we saw a few days ago. Let me know why? ^_^

========================================================== ====

Finally, I want to say that there are many friends who read this note during this time, but no one will respond. Make me feel depressed, I

I just hope that it will serve as an example. I hope more brothers can learn and improve together and help me .. Ah

Oh... I hope you can leave a message .. Pai_^

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.