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 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 ){