TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
一、主程序
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class splashScreenDemo extends
MIDlet implements CommandListener {
private Command exitCommand;
private Display display = null;
private boolean firstTime = true; private TextBox tb;
public splashScreenDemo(){
exitCommand = new Command("Exit", Command.EXIT, 1); tb = new TextBox("主程序", "主界面!", 15, 0);
tb.addCommand(exitCommand); tb.setCommandListener(this);
display = Display.getDisplay(this);
}
- protected void startApp() throws MIDletStateChangeException {
- if (firstTime) {
- splashScreen welcome = new splashScreen(display, tb);
- welcome.setDisplayTime(6000);
- display.setCurrent(welcome);
- firstTime = false;
- }
- }
- protected void pauseApp() {
- }
- protected void destroyApp(boolean d) {
- }
- public void commandAction(Command c, Displayable d) {
- if (c == exitCommand) {
- destroyApp(false);
- notifyDestroyed();
- }
- }
- }
- 二、欢迎画面:
- import java.io.IOException;
- import java.util.Timer;
- import java.util.TimerTask;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- public class splashScreen extends Canvas {
- private Display display;
- private Displayable nextDisplay;
- private Timer timer = new Timer();
- private long displayTime = 3000;
- public splashScreen(Display dis, Displayable disp) {
- this.display = dis;
- this.nextDisplay = disp;
- }
- protected void paint(Graphics g) {
- int width = this.getWidth();
- int height = this.getHeight();
- g.drawString("这是欢迎界面",width/2,50,Graphics.TOP|Graphics.HCENTER);
- Image displayImage = null;
- try {
- displayImage = Image.createImage("/computer.png");
- } catch (IOException e) {
- e.printStackTrace();
- }
- g.drawImage(displayImage, width / 2, height / 2 + displayImage.getHeight() / 2,
- Graphics.HCENTER|Graphics.BOTTOM);
- }
- public void setDisplayTime(long dispTime) {
- this.displayTime = dispTime;
- }
- protected void keyPressed(int keyCode) {
- disappear();
- }
- protected void pointerPressed(int y, int x) {
- disappear();
- }
- private void disappear() {
- timer.cancel();
- display.setCurrent(nextDisplay);
- }
- protected void showNotify() {
- timer.schedule(new TimerTask() {
- public void run() {
- disappear();
- }
- }, displayTime);
- }
- }
- 三、运行图
- [img]http://img.javaxxz.com/2014/10/11/081208062.jpg[/img] [img]http://img.javaxxz.com/2014/10/11/081208125.jpg[/img]
复制代码
源码下载:http://203.93.208.26/kj/cwb/dir7/splnDemo.zip |
|