midlet3.java

来自「这是郭克华老师的J2ME视频的源代码」· Java 代码 · 共 55 行

JAVA
55
字号
package prj22_1;

import java.util.Random;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class MIDlet3 extends MIDlet {
	private MyGameCanvas mgc = new MyGameCanvas();
	private Display dis;
	protected void startApp() throws MIDletStateChangeException {
		dis = Display.getDisplay(this);
		dis.setCurrent(mgc);

	}
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		

	}

	protected void pauseApp() {
		

	}
	
	class MyGameCanvas extends GameCanvas implements Runnable{
		private boolean RUN = true;
		private Random rnd = new Random();
		private Graphics gra;
		public MyGameCanvas(){
			super(true);
			gra = this.getGraphics();
			new Thread(this).start();
		}		
		public void run(){
			while(RUN){
				try{
					//直接访问画笔重画					
					gra.drawLine(rnd.nextInt(this.getWidth()),rnd.nextInt(this.getHeight()),
								rnd.nextInt(this.getWidth()),rnd.nextInt(this.getHeight()));
					this.flushGraphics();
					
					Thread.currentThread().sleep(100);
				}catch(Exception ex){}
			}
		}

	}


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?