• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mike McMahon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike McMahon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it!

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

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic