public class TryPolyLine
{
public static void main(String[] args)
{
TryPolyLine tpl = new TryPolyLine();
Point[] coords={tpl.new Point(1.0,1.0), tpl.new Point(2.0,2.0), tpl.new Point(3.0,3.0), tpl.new Point(4.0,4.0), tpl.new Point(5.0,5.0), tpl.new Point(6.0,6.0)};
TryPolyLine.PolyLine polygon=tpl.new PolyLine(coords);
System.out.println(polygon);
polygon.addPoint(tpl.new Point(7.0,7.0));
System.out.println(polygon);
Point[] points=new Point[coords.length];
for(int i=0;i<points.length;i++)
{
points[i]=tpl.new Point(coords[i].x,coords[i].y);
TryPolyLine.PolyLine newPoly=tpl.new PolyLine(points);
System.out.println(newPoly);
}
}
class Point
{
public Point(double xVal,double yVal)
{
x=xVal;
y=yVal;
} public Point(Point point)
{
x=point.x;
y=point.y;
} public String tostring()
{
return x+","+y;
} protected double x;
protected double y;
} class ListPoint
{
public ListPoint(Point point)
{
this.point=point;
next=null;
} public void setNext(ListPoint next)
{
this.next=next;
} public ListPoint getNext()
{
return next;
} public String tostring()
{
return "("+point+")";
} private ListPoint next;
private Point point;
} class PolyLine
{
public ListPoint start;
public ListPoint end;
public PolyLine(Point[] points)
{
if(points!=null)
{
start=new ListPoint(points[0]);
end=start;
for(int i=1;i<points.length;i++)
{
addPoint(points[i]);
}
}
} public void addPoint(Point point)
{
ListPoint newEnd=new ListPoint(point);
if(start==null)
start=newEnd;
else
end.setNext(newEnd);
end=newEnd;
} public String tostring()
{
StringBuffer str=new StringBuffer("PolyLine:");
ListPoint nextPoint=start;
while(nextPoint!=null)
{
str.append(" "+nextPoint);
nextPoint=nextPoint.getNext();
}
return str.toString();
}
}}//这是我修改过后的,自己对照一下吧
{
public static void main(String[] args)
{
TryPolyLine tpl = new TryPolyLine();
Point[] coords={tpl.new Point(1.0,1.0), tpl.new Point(2.0,2.0), tpl.new Point(3.0,3.0), tpl.new Point(4.0,4.0), tpl.new Point(5.0,5.0), tpl.new Point(6.0,6.0)};
TryPolyLine.PolyLine polygon=tpl.new PolyLine(coords);
System.out.println(polygon);
polygon.addPoint(tpl.new Point(7.0,7.0));
System.out.println(polygon);
Point[] points=new Point[coords.length];
for(int i=0;i<points.length;i++)
{
points[i]=tpl.new Point(coords[i].x,coords[i].y);
TryPolyLine.PolyLine newPoly=tpl.new PolyLine(points);
System.out.println(newPoly);
}
}
class Point
{
public Point(double xVal,double yVal)
{
x=xVal;
y=yVal;
} public Point(Point point)
{
x=point.x;
y=point.y;
} public String tostring()
{
return x+","+y;
} protected double x;
protected double y;
} class ListPoint
{
public ListPoint(Point point)
{
this.point=point;
next=null;
} public void setNext(ListPoint next)
{
this.next=next;
} public ListPoint getNext()
{
return next;
} public String tostring()
{
return "("+point+")";
} private ListPoint next;
private Point point;
} class PolyLine
{
public ListPoint start;
public ListPoint end;
public PolyLine(Point[] points)
{
if(points!=null)
{
start=new ListPoint(points[0]);
end=start;
for(int i=1;i<points.length;i++)
{
addPoint(points[i]);
}
}
} public void addPoint(Point point)
{
ListPoint newEnd=new ListPoint(point);
if(start==null)
start=newEnd;
else
end.setNext(newEnd);
end=newEnd;
} public String tostring()
{
StringBuffer str=new StringBuffer("PolyLine:");
ListPoint nextPoint=start;
while(nextPoint!=null)
{
str.append(" "+nextPoint);
nextPoint=nextPoint.getNext();
}
return str.toString();
}
}}//这是我修改过后的,自己对照一下吧
解决方案 »
- java sql2005 JTable 表连接 数据传入 好头痛 啊 想哭啦
- PNG图片压缩过程中提取数据的问题
- JAVA新手-怎么获得键盘输入???
- 静态内部类-强制转换时出错?
- 问题:没有显示出错误,但是输不出自己想的要结果。
- 迷惑中!窗口刚启动时,标题栏是活动状态的。并且焦点也在JtextField闪动,但就是输不了值!
- 求助怎么删除节点
- 紧急求救:谁有sysbase的在win200下的odbc驱动?(200分送上!在sysbase区没人理)
- 急~~~我的一个APPLET想把客户选择的内容复制到WINDOWS剪切板
- 该如何使用jdbc?
- 类的可见性的问题,分数不是很多,也请多多帮忙!
- 简单问题请各位帮忙啊
{
public TryPolyLine()
{
Point[] coords={new Point(1.0,1.0),new Point(2.0,2.0),new Point(3.0,3.0),new Point(4.0,4.0),new Point(5.0,5.0),new Point(6.0,6.0)};
PolyLine polygon=new PolyLine(coords);
System.out.println(polygon);
polygon.addPoint(new Point(7.0,7.0));
System.out.println(polygon);
Point[] points=new Point[coords.length];
for(int i=0;i<points.length;i++)
{
points[i]=new Point(coords[i].x,coords[i].y);
PolyLine newPoly=new PolyLine(points);
System.out.println(newPoly);
}
}
public static void main(String[] args)
{
TryPolyLine tpl = new TryPolyLine();
} private class Point
{
public Point(double xVal,double yVal)
{
x=xVal;
y=yVal;
}
public Point(Point point)
{
x=point.x;
y=point.y;
}
public String tostring()
{
return x+","+y;
}
protected double x;
protected double y;
}
public class ListPoint
{
public ListPoint(Point point)
{
this.point=point;
next=null;
}
public void setNext(ListPoint next)
{
this.next=next;
}
public ListPoint getNext()
{
return next;
}
public String tostring()
{
return "("+point+")";
}
private ListPoint next;
private Point point;
}
public class PolyLine
{
public ListPoint start;
public ListPoint end;
public PolyLine(Point[] points)
{
if(points!=null)
{
start=new ListPoint(points[0]);
end=start;
for(int i=1;i<points.length;i++)
{
addPoint(points[i]);
}
}
}
public void addPoint(Point point)
{
ListPoint newEnd=new ListPoint(point);
if(start==null)
start=newEnd;
else
end.setNext(newEnd);
end=newEnd;
}
public String tostring()
{
StringBuffer set=new StringBuffer("PolyLine:");
ListPoint nextPoint=start;
while(nextPoint!=null)
{
set.append(" "+nextPoint);
nextPoint=nextPoint.getNext();
}
return set.toString();
}
}
}