608d7cf44899001b138cd89f505b592c

来自「《J2ME实用教程》 源文件下载 本书没有仅仅局限于J2ME单机游戏的开发」· 代码 · 共 31 行

TXT
31
字号
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class SimpleGraphic extends MIDlet implements CommandListener {
	private Command exitCommand;
	private SimpleGraphicCanvas sg;
	public SimpleGraphic() {
		exitCommand = new Command("Exit", Command.EXIT, 1);
		sg = new SimpleGraphicCanvas();
		sg.addCommand(exitCommand);
		sg.setCommandListener(this);
		Display.getDisplay(this).setCurrent(sg);
		}
	public void commandAction(Command c, Displayable d) {
		if (c == exitCommand) {			
			destroyApp(false);			
			notifyDestroyed();
		}
	}	
}

class SimpleGraphicCanvas extends Canvas{
	protected void paint(Graphics g) {
		//绘制直线
		g.drawLine(0,0,150,150);
		//绘制矩形
		g.fillRect(150,100,40,40);
		//绘制填充矩形
		g.drawRect(80,60,50,80)
		}
}

⌨️ 快捷键说明

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