point.java.svn-base

来自「利用J2ME编写的手机应用程序。 功能包括显示图片」· SVN-BASE 代码 · 共 65 行

SVN-BASE
65
字号
package wFramework;

public class Point 
{
	public int x, y;
	
	public Point(String str)
	{
		parseString(str);
	}
	
	public Point(int x, int y)
	{
		this.x = x;
		this.y = y;
	}
	
	public void parseString(String str)
	{
		if (str.startsWith("POINT"))
		{
			int s = -1;
			x = -1;
			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)
						return;
					s = -1;
				}
			}
		}
	}
	
	public double distance(Point other)
	{
		return Math.sqrt((double)distance2(other));
	}
	
	public int distance2(Point other)
	{
		int dx = other.x - x;
		int dy = other.y - y;
		return dx * dx + dy * dy;
	}
	
	public String toString()
	{
		return String.valueOf(x) + ", " + String.valueOf(y);
	}

}

⌨️ 快捷键说明

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