File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Trying to use an existing java.awt.Polygon in my JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to use an existing java.awt.Polygon in my JSP" Watch "Trying to use an existing java.awt.Polygon in my JSP" New topic
Author

Trying to use an existing java.awt.Polygon in my JSP

Mike McMahon
Ranch Hand

Joined: May 07, 2005
Posts: 30
Hi,

I have a super simple jsp in which I'm trying to take advantage of an existing class (java.awt.Polygon). Info on that class is here - http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Polygon.html.

Basically, it works if I only provide 4 xy pairs. If I add a 5th pair, it fails - "java.lang.ArrayIndexOutOfBoundsException: 4". I'm a newb, but it seems that I've provided more xy pairs than the array can hold. However, I defined polygon1.npoints=5 - so shouldn't it be able to hold 5 pairs?

Thanks for any tips - my jsp is below...

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
You shouldn't access the internal fields npoints, xpoints and ypoints. The way to add points to a Polygon is to use the addPoint(x,y) method.


Ping & DNS - updated with new look and Ping home screen widget
Mike McMahon
Ranch Hand

Joined: May 07, 2005
Posts: 30
Aaaahhhhh. Ok - thanks.

If I can be permitted a follow up...

So, if I have hundreds of points I want to add (from a db), I could throw them into arrays (or arrayLists) - one for x coords, one for y coords, and use a for loop to load them?

I tried this with the code below, but I'm getting an error - "The method addpoints(int, int) is undefined for the type Polygon". The method says "addPoint(int x, int y) Appends the specified coordinates to this Polygon."

What have I missed?

Thanks so much - I'm miles ahead of where I was!

Mike McMahon
Ranch Hand

Joined: May 07, 2005
Posts: 30
I got it!

If I've got arrays of x and y coords, I can instantiate the polygon from them directly.

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to use an existing java.awt.Polygon in my JSP
 
Similar Threads
Good User Interface
Polygon()
Java geometry - coordinates, points
PathIterator returns the last point twice?
Showing relationship in inline frames