Learning notes for j2-based learning platform (6)

Source: Internet
Author: User

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

Related Article

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.