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

📄 polyline.java.svn-base

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

import java.util.Vector;

import javax.microedition.lcdui.Graphics;

public class Polyline 
{
	private Vector points;

	public Polyline()
	{
		points = new Vector();
	}
	
	public Polyline(String str)
	{
		points = new Vector();
		parseString(str);
	}
	
	public void parseString(String str)
	{
		points.removeAllElements();
		if (str.startsWith("LINE"))
		{
			int s = -1;
			int x = -1;
			int y = -1;
			for (int i = 0; i < str.length(); i++)
			{
				if (Character.isDigit(str.charAt(i)) || str.charAt(i) == '.')
				{
					if (s < 0)
						s = i;
				}
				else if (s >= 0)
				{
					if (x < 0)
						x = (int)(Float.parseFloat(str.substring(s, i)) + 0.5f);
					else
						y = (int)(Float.parseFloat(str.substring(s, i)) + 0.5f);
					
					if (x >= 0 && y >= 0)
					{
						points.addElement(new Point(x, y));
						x = -1;
						y = -1;
					}
					s = -1;
				}
			}
		}
	}

	public int getNumPoints()
	{
		return points.size();
	}
	
	public Point getPoint(int i)
	{
		if (i >= 0 && i < points.size())
			return (Point)points.elementAt(i);
		else
			return null;
	}
	
	public Point getCenter()
	{
		if (points.size() < 1) return null;		
		Point center = new Point(0, 0);
		for (int i = 0; i < points.size(); i++)
		{
			Point p = (Point)points.elementAt(i);
			if (i == 0)
			{
				center.x = p.x;
				center.y = p.y;
			}
			else
			{
				center.x += p.x;
				center.y += p.y;
			}
		}
		center.x /= points.size();
		center.y /= points.size();		
		return center;
	}

	/**
	 * Draws polyline using built in coordinates
	 * @param g
	 */
	public void paint(Graphics g)
	{
		for (int i = 0; i < points.size() - 1; i++)
		{
			Point p0 = (Point)points.elementAt(i);
			Point p1 = (Point)points.elementAt(i + 1);
			g.drawLine(p0.x, p0.y, p1.x, p1.y);
		}		
	}
	
	/**
	 * Draws the polyline using pixel transform from map
	 * @param g
	 * @param m
	 */
	public void paint(Graphics g, Map m)
	{
		for (int i = 0; i < points.size() - 1; i++)
		{
			Point p0 = m.worldToPixel((Point)points.elementAt(i));
			Point p1 = m.worldToPixel((Point)points.elementAt(i + 1));
			g.drawLine(p0.x, p0.y, p1.x, p1.y);
		}
	}
	
	public String toString()
	{
		return "";
	}
}

⌨️ 快捷键说明

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