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

📄 drawfonttest.java~2~

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

public class DrawFontTest extends MIDlet implements CommandListener{

	Display display;
	MyCanvas myCanvas;
	ChoiceGroup setVertical, setHorizontal;
	Form form;
	Command okCmd;

	public DrawFontTest(){
		display = Display.getDisplay(this);
		myCanvas = new MyCanvas();
		form = new Form("选择排版方式");
		okCmd = new Command("确定", Command.OK, 1);
		setVertical = new ChoiceGroup("垂直方向", List.EXCLUSIVE);
		setVertical.append("TOP", null);
		setVertical.append("BASELINE", null);
		setVertical.append("BOTTOM", null);
		setHorizontal = new ChoiceGroup("水平方向", List.EXCLUSIVE);
		setHorizontal.append("LEFT", null);
		setHorizontal.append("HCENTER", null);
		setHorizontal.append("RIGHT", null);
		form.append(setVertical);
		form.append(setHorizontal);
		form.addCommand(okCmd);
		form.setCommandListener(this);
	}


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

	public void pauseApp(){

	}


	public void destroyApp(boolean unconditional){

	}

	public void commandAction(Command c, Displayable d){

		if(c == okCmd){
			int index = setVertical.getSelectedIndex();
			switch(index){
				case 0:
					myCanvas.vertical = Graphics.TOP;
				break;
				case 1:
					myCanvas.vertical = Graphics.BASELINE;
				break;
				case 2:
					myCanvas.vertical = Graphics.BOTTOM;
				break;
			}
			index = setHorizontal.getSelectedIndex();
			switch(index){
				case 0:
					myCanvas.horizontal = Graphics.LEFT;
				break;
				case 1:
					myCanvas.horizontal = Graphics.HCENTER;
				break;
				case 2:
					myCanvas.horizontal = Graphics.RIGHT;
				break;
			}
		}
		myCanvas.repaint();
		display.setCurrent(myCanvas);
	}


	class MyCanvas extends Canvas implements CommandListener{

		int vertical;
		int horizontal;
		Command exitCmd;
		Command changeCmd;

		public MyCanvas(){
			exitCmd = new Command("退出", Command.EXIT, 1);
			changeCmd = new Command("改变", Command.SCREEN, 1);
			addCommand(exitCmd);
			addCommand(changeCmd);
			setCommandListener(this);
		}

		public void paint(Graphics g){

			g.setColor(0xFFFFFF);
			g.fillRect(0, 0, getWidth(), getHeight());
			g.setColor(0);
			g.drawString("Test", getWidth()/2, getHeight()/2, vertical|horizontal);
			g.setColor(0xFF0000);
			g.drawLine(getWidth()/2, 0, getWidth()/2, getHeight());
			g.drawLine(0, getHeight()/2, getWidth(), getHeight()/2);
		}

		public void commandAction(Command c, Displayable d){

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

⌨️ 快捷键说明

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