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

📄 test.java

📁 canvas-yxifu j2me 源码 canvas类与MIDlet类结合实例
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class test extends MIDlet implements CommandListener
{	private int currentFace=Font.FACE_SYSTEM;
	private Command monospaceCommand=new Command("monospace",Command.ITEM,1);
	private Command proportionalCommand=new Command("proportional",Command.ITEM,1);
	private Command systemCommand=new Command("system",Command.ITEM,1);
	private graph gra=new graph();
	protected void startApp()
	{	gra.setCommandListener(this);
		Display.getDisplay(this).setCurrent(gra);
	}
	protected void destroyApp(boolean unconditional){}
	protected void pauseApp(){}
	public void commandAction(Command command,Displayable displayable)
	{	if(command.getCommandType()==Command.EXIT)
		{	destroyApp(false);
			notifyDestroyed();
			return;
		}//MIDlet1.quitApp();
		if(command==monospaceCommand)
			currentFace=Font.FACE_MONOSPACE;
		else if(command==proportionalCommand)
			currentFace=Font.FACE_PROPORTIONAL;
		else if(command==systemCommand)
			currentFace=Font.FACE_SYSTEM;
		gra.repaint();
	}
	class graph extends Canvas
	{	public graph()
		{	try{
			addCommand(new Command("Exit",Command.EXIT,1));
			//gra.setCommandListener(this);
			addCommand(monospaceCommand);
			addCommand(proportionalCommand);
			addCommand(systemCommand);
			}catch(Exception e){e.printStackTrace();}
		}
		protected void paint(Graphics g)
		{	String title;
			int height=0;
			g.setColor(0x00000ff0);
			g.fillRect(0,0,getWidth(),getHeight());
			g.setColor(0x00FFFFFF);
			switch(currentFace)
			{
			case Font.FACE_SYSTEM:
				title="System";
				break;
			case Font.FACE_PROPORTIONAL:
				title="Proportional";
				break;
			case Font.FACE_MONOSPACE:
				title="Monospace";
				break;
			default:
				title="unknown";
			}
			g.drawString(title,0,0,Graphics.TOP|Graphics.LEFT);
			height+=g.getFont().getHeight();
			g.setFont(Font.getFont(currentFace,Font.STYLE_PLAIN,Font.SIZE_LARGE));
			g.drawString("Regular plain",0,height,Graphics.TOP|Graphics.LEFT);
			height+=g.getFont().getHeight();
			g.setFont(Font.getFont(currentFace,Font.STYLE_ITALIC,Font.SIZE_LARGE));
			g.drawString("Regular plain",0,height,Graphics.TOP|Graphics.LEFT);
			height+=g.getFont().getHeight();
			g.setFont(Font.getFont(currentFace,Font.STYLE_BOLD,Font.SIZE_LARGE));
			g.drawString("Regular plain",0,height,Graphics.TOP|Graphics.LEFT);
			height+=g.getFont().getHeight();
			g.setFont(Font.getFont(currentFace,Font.STYLE_BOLD|Font.STYLE_ITALIC,Font.SIZE_LARGE));
			g.drawString("Regular plain",0,height,Graphics.TOP|Graphics.LEFT);
		}
	}
}
 

⌨️ 快捷键说明

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