Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Polyline question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Polyline question" Watch "Polyline question" New topic
Author

Polyline question

Ravi Kotha
Ranch Hand

Joined: Mar 02, 2006
Posts: 53
Hi,

Is there a class in Java that supports Polyline. Lets say I have points (10,20) (20,30) (40,50) (60,70). Can I construct a line with all these points. I saw in java.awt.geom package, there is a class Line2D, but it can take only two points. What if I wanna construct a line with 'n' points?
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
I don't think there is, but you shouldn't have too much of a problem rolling your own.


[ January 03, 2007: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The Graphics class lists a method with this signature

Another useful class is GeneralPath. moveTo the first set of coordinates and lineTo each of the next in sequence. For a closed path (optional) either closePath or lineTo the initial set of coordinates.
Ravi Kotha
Ranch Hand

Joined: Mar 02, 2006
Posts: 53
Thanks Rowe


My problem is not drawing lines. Lets say I have set of points coming from the front end (10,20) (30,50), (45,67), (87,34). Using these points I want to form a polyline which includes all the points. How can I do that?
Ravi Kotha
Ranch Hand

Joined: Mar 02, 2006
Posts: 53
Thanks Craig,

Hope it will be helpful.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Polyline question
 
Similar Threads
How to get all attributes of a tag in an XML document using javascript?
Drawing Lines by Angles
PolyLine or Polygon?
Javascript not detecting argument passed by JSP code
Google Map API : Drawing curve line between two Points .