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

📄 mapoverlaytext.java.svn-base

📁 利用J2ME编写的手机应用程序。 功能包括显示图片
💻 SVN-BASE
字号:
package wFramework;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class MapOverlayText extends MapOverlay 
{
	private String text;
	private int color;
	private Font font;
	private Image background;

	public MapOverlayText(Map map, Point pos, String text, Object param)
	{
		super(map, pos, param);
		this.text = text;
		color = 0x000000;
		this.font = Font.getFont(Font.FONT_STATIC_TEXT, Font.STYLE_PLAIN, Font.SIZE_SMALL);
		background = null;
		updateBounds();
	}

	public void setText(String text)
	{
		this.text = text;
		updateBounds();
	}

	public String getText()
	{
		return text;
	}

	public int getColor()
	{
		return color;
	}

	public void setColor(int color)
	{
		this.color = color;
	}
	
	public void setFont(Font font)
	{
		if (this.font != font)
		{
			this.font = font;
			updateBounds();
		}
	}
	
	private Image makeFillImage(int width, int height)
	{
		int data[] = new int[width * height];
		for (int i = 0; i < width * height; i++)
			data[i] = 0x80ffffff;
		return Image.createRGBImage(data, width, height, true);	
	}

	public void paint(Graphics g)
	{
		Point px = map.worldToPixel(pos);
		g.setFont(font);

		//g.setColor(0xffffff);
		//g.fillRoundRect(px.x + bounds.p.x - bounds.e.x, px.y + bounds.p.y - bounds.e.y, bounds.e.x * 2, bounds.e.y * 2, 8, 8);
		g.drawImage(background, px.x, px.y + bounds.p.y - bounds.e.y, Graphics.HCENTER | Graphics.TOP);
		g.setColor(color);
		g.drawString(text, px.x, px.y + bounds.p.y - bounds.e.y, Graphics.HCENTER | Graphics.TOP);
	}
	
	private void updateBounds()
	{
		int w = font.stringWidth(text) + 2;
		int h = font.getHeight();
		int x0 = -w / 2;
		int y0 = -h / 2;
		bounds = new Rect(x0, y0, x0 + w, y0 + h);
		background = makeFillImage(w, h);
	}
}

⌨️ 快捷键说明

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