GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Get Area of a Polygon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Get Area of a Polygon" Watch "Get Area of a Polygon" New topic
Author

Get Area of a Polygon

Patrick Thorse
Greenhorn

Joined: Jun 15, 2001
Posts: 5
How do I get the area of a polygon? Seems like there should be a way to do that but I haven't found ANYTHING.........
Seems like there should be a polygon.getArea command?
Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
Hi Patrick,
This is a function that would return the area of a Polygon whose vertices are given as the first parameter and the no. of sides is given as the second parameter.

-------------
Amit
[This message has been edited by Amit Agarwal (edited July 01, 2001).]
Patrick Thorse
Greenhorn

Joined: Jun 15, 2001
Posts: 5
Amit,
Thank you very much. The area function worked perfect!
One more question. I have an applet that allows me to draw a polygon and then edit the polygon by 'tugging' on each of the nodes to change the geometry of the polygon. How do I refresh the screen without using paint()? After I move the nodes around, graphics remain on the screen that are not desired. If I minimize the browser window and then maximize it, the screen looks correct, with the old graphics removed.
Thanks,
Patrick
[This message has been edited by Patrick Thorse (edited July 03, 2001).]
Daniel Searson
Ranch Hand

Joined: Dec 03, 2000
Posts: 83
Just call repaint() on the panel (or applet) you want to redraw. If you're using the AWT (not Swing) you might want to add a back-buffer to get rid of flickering.
Daniel


- Daniel
Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
Patrick,
In your paint() add a statement to clear the panel in the beginning and redraw the polygon etc. use g.clearRect(0,0,getWidth(),getHeight()); if you have a background color, set the color and instead of clearRect() use fillRect(). Use double buffering in swing to get flicker free drawing.
Amit
 
Don't get me started about those stupid light bulbs.
 
subject: Get Area of a Polygon