• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic