Java Swing custom shapes (2D Graphics)
- by juFo
I need to draw custom shapes. Now when a user clicks on several points on the panel I create a shape using a polygon.
public void mouseClicked(MouseEvent e) {
polygon.addPoint(e.getX(), e.getY());
repaint();
}
But I don't know if this is the best way to draw custom shapes.
It should be possible to edit a drawn shape:
resize
change its fill color
change the stroke color
copy/paste it
move a single point of the polygon
...
I have seen people creating an own class implementing the Shape class and using a GeneralPath. But again I have no idea if this is a good way.
Now I can create my own shape with a polygon (or with a GeneralPath) but I have no clue how to attach all the edit functions to my own shape (the edit functions I mean the resize, move, etc from above).
I hope somebody could show me a way to do this or maybe write a little bit of code to demonstrate this.
Thanks in advance!!