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

📄 fonttest.java~2~

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

public class FontTest extends MIDlet implements CommandListener{

	Display display;
	MyCanvas myCanvas;
	Command exitCmd;
	Command okCmd;
	Form form;
	ChoiceGroup face, size, style;

	public FontTest(){
		display = Display.getDisplay(this);
		myCanvas = new MyCanvas(this);
		form = new Form("选择字型");
		face = new ChoiceGroup("Face", List.EXCLUSIVE);
		size = new ChoiceGroup("Size", List.EXCLUSIVE);
		style = new ChoiceGroup("Style", List.MULTIPLE);
		exitCmd = new Command("退出", Command.EXIT, 1);
		okCmd = new Command("确定", Command.OK, 1);

		face.append("SYSTEM",null);
		face.append("PROPORTIONAL",null);
		face.append("MONOSPACE",null);
		size.append("LARGE",null);
		size.append("MEDIUM  ",null);
		size.append("SMALL ",null);
		style.append("BOLD",null);
		style.append("ITALIC",null);
		style.append("UNDERLINED",null);
		form.append(face);
		form.append(size);
		form.append(style);
		form.addCommand(exitCmd);
		form.addCommand(okCmd);
		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 == okCmd){
			int setFace = face.getSelectedIndex();
			int setSize = size.getSelectedIndex();
			boolean[] setStyle = new boolean[3];
			style.getSelectedFlags(setStyle);
			myCanvas.setFont(setFace, setSize, setStyle);
			display.setCurrent(myCanvas);

		}
	}

}

class MyCanvas extends Canvas implements CommandListener{

	Font Font;
	FontTest midlet;
	Command backCmd;
	int face, size, style;

	public MyCanvas(FontTest midlet){
		this.midlet = midlet;
		backCmd = new Command("返回", Command.BACK, 1);
		addCommand(backCmd);
		setCommandListener(this);
	}

	public void paint(Graphics g){

		g.setColor(0xFFFFFF);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(0);
		g.setFont(Font.getFont(face, style, size));
		g.drawString("Font Test", getWidth()/4, getHeight()/2, Graphics.TOP|Graphics.LEFT);

	}

	public void setFont(int face, int size, boolean[] selectedArray){

		switch(face){
			case 0: this.face = Font.FACE_SYSTEM; break;
			case 1: this.face = Font.FACE_PROPORTIONAL; break;
			case 2: this.face = Font.FACE_MONOSPACE; break;
		}
		switch(size){
			case 0: this.size = Font.SIZE_LARGE; break;
			case 1: this.size = Font.SIZE_MEDIUM; break;
			case 2: this.size = Font.SIZE_SMALL; break;

		}
		if(selectedArray[0]){
			style |= Font.STYLE_BOLD;
		}
		if(selectedArray[1]){
			style |= Font.STYLE_ITALIC;
		}
		if(selectedArray[2]){
			style |= Font.STYLE_UNDERLINED;
		}
	}

	public void commandAction(Command c, Displayable d){
		if(c == backCmd){
			midlet.display.setCurrent(midlet.form);
		}
	}

}

⌨️ 快捷键说明

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