⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 midlet3.java

📁 这是郭克华老师的J2ME视频的源代码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -