• Post Reply Bookmark Topic Watch Topic
  • New Topic

polygon editor

 
Anna Amatus
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all,

I need to create a swing utility to draw and manipulate polygons (both regular and irregular).
Quite simple stuff, create the polygon by mouse click on the vertices positions on the screen + move, delete and add vertices.
Before starting from scratch I was wondering if there are some library or free code that I can start from.

Thanks!
Anna.
 
Campbell Ritchie
Marshal
Posts: 52590
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There probably is but I don't know about it.

You can set up a mouse listener on your panel which records the location of the click and adds it to a path. A GeneralPath object might be useful.
 
Tim Moores
Saloon Keeper
Posts: 3263
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JGraphX might fit that bill.
 
Rob Camick
Ranch Hand
Posts: 2701
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating the Polygon is easy. You just use the MouseListener and add Points to a Polygon class.

Manipulating the Points will be more difficult. It will be hard to click on the exact Point of the Vertex so you will need to probably write an algorithm to find the closest Point to where the mouse is clicked in order to do the manipulations.
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!