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

📄 simplegraphic_2.java

📁 《精通JAVA手机游戏与应用程序设计》随书光盘
💻 JAVA
字号:

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

/*
 * 绘制字符串
 */
public class SimpleGraphic_2 extends MIDlet implements CommandListener {

	private Command exitCommand;
	private SimpleGraphicCanvas_2 sg;

	public SimpleGraphic_2() {
		exitCommand = new Command("Exit", Command.EXIT, 1);
		sg = new SimpleGraphicCanvas_2();
		sg.addCommand(exitCommand);
		sg.setCommandListener(this);
		Display.getDisplay(this).setCurrent(sg);
		
	}
	protected void startApp(){
	}

	protected void pauseApp() {
	}

	protected void destroyApp(boolean arg0){		
	}
	public void commandAction(Command c, Displayable d) {
		if (c == exitCommand) {			
			destroyApp(false);			
			notifyDestroyed();
		}
	}	
}

class SimpleGraphicCanvas_2 extends Canvas{
	
	protected void paint(Graphics g) {
		int x=0,y=0;		
		g.drawString("原点", x, y, Graphics.TOP|Graphics.LEFT);
		g.drawString("TOP|LEFT", 40, 40, Graphics.TOP|Graphics.LEFT);
		g.drawString("BOTTOM|LEFT", 40, 40,Graphics.BOTTOM|Graphics.LEFT);
		//Font f = Font.getDefaultFont();
	    //g.drawString(str, x + f.stringWidth(str)/2, y, Graphics.TOP|Graphics.HCENTER);
	   // g.drawString(str, x + f.stringWidth(str), y, Graphics.TOP|Graphics.RIGHT);

	  /*  g.drawString(str, x,
	        y + f.getBaselinePosition(), Graphics.BASELINE|Graphics.LEFT);
	    g.drawString(str, x + f.stringWidth(str)/2,
	        y + f.getBaselinePosition(), Graphics.BASELINE|Graphics.HCENTER);
	    g.drawString(str, x + f.stringWidth(str),
	        y + f.getBaselinePosition(), Graphics.BASELINE|Graphics.RIGHT);

	    g.drawString(str, x,
	        y + f.getHeight(), Graphics.BOTTOM|Graphics.LEFT);
	    g.drawString(str, x + f.stringWidth(str)/2,
	        y + f.getHeight(), Graphics.BOTTOM|Graphics.HCENTER);
	    g.drawString(str, x + f.stringWidth(str),
	        y + f.getHeight(), Graphics.BOTTOM|RIGHT);*/
		
	}
	
}

⌨️ 快捷键说明

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