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

📄 repainttest.java

📁 java手机程序开发随书光盘源代码
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class RepaintTest extends MIDlet implements CommandListener{

	Display display;
	MyCanvas myCanvas;
	Form form;
	Command exitCmd;
	Command changeCmd;

	public RepaintTest(){
		display = Display.getDisplay(this);
		exitCmd = new Command("退出", Command.EXIT, 1);
		changeCmd = new Command("更换", Command.SCREEN, 1);
		myCanvas = new MyCanvas();
		form = new Form("另一个Displayable");
		form.append("Hide Canvas!");
		form.addCommand(exitCmd);
		form.addCommand(changeCmd);
		form.setCommandListener(this);
	}


	public void startApp(){
		display.setCurrent(form);
	}

	public void pauseApp(){

	}

	public void destroyApp(boolean unconditional){

	}

	public void commandAction(Command c, Displayable d){

		if(c == exitCmd){
			destroyApp(true);
			notifyDestroyed();
		}
		else if(c == changeCmd && d == form){
			display.setCurrent(myCanvas);
		}
	}


	class MyCanvas extends Canvas implements CommandListener{

		Command repaintCmd;

		public MyCanvas(){
			repaintCmd = new Command("重画", Command.SCREEN, 1);
			addCommand(changeCmd);
			addCommand(repaintCmd);
			setCommandListener(this);
		}

		public void paint(Graphics g){
			g.setColor(0xFFFFFF);
			g.fillRect(0, 0, getWidth(), getHeight());
			System.out.println("paint() is called!");
		}

		public void showNotify(){
			System.out.println("showNotify() is called!");
		}

		public void hideNotify(){
			System.out.println("hideNotify() is called!");
		}

		public void commandAction(Command c, Displayable d){

			if(c == changeCmd && d == this){
				display.setCurrent(form);
			}
			else if(c == repaintCmd){
				repaint();
			}
		}
	}
}

⌨️ 快捷键说明

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