In the compiling process of the j2_game, it is common to make a welcome interface. The following describes how to make a welcome interface.
There are two methods to implement the welcome interface:
1. Press any key to enter the main interface of the system.
2. Wait n seconds (n <6) before entering the main interface
The implementation code is as follows:
// Press any key to enter the main interface
Import javax. microedition. lcdui .*;
Public class WelcomeCanvas extends Canvas {
// Background image
Image bgImage = null;
Display display;
Public WelcomeCanvas (Display display ){
This. display = display;
// Import the image
Try {
BgImage = Image. createImage ("/res/welcome.png ");
} Catch (Exception e ){
Alert a = new Alert ("error", "The resource file does not exist! ", Null, AlertType. ERROR );
A. setTimeout (Alert. FOREVER );
// Display the prompt box
Display. setCurrent ();
}
}
Protected void paint (Graphics g ){
// Draw a background image
G. drawImage (bgImage, 0, 0, Graphics. TOP | Graphics. LEFT );
}
Protected void keyPressed (int keyCode ){
// Display the interface to be displayed
Display. setCurrent (new MainList ());
}
}
// Automatically enters the main interface five seconds later
Import javax. microedition. lcdui .*;
Public class WelcomeCanvas extends Canvas implements Runnable {
// Background image
Image bgImage = null;
Display display;
Public WelcomeCanvas (Display display ){
This. display = display;
// Import the image
Try {
BgImage = Image. createImage ("/res/welcome.png ");
} Catch (Exception e ){
Alert a = new Alert ("error", "The resource file does not exist! ", Null, AlertType. ERROR );