I am trying to draw shapes (triangle, rectangle, square and circle) that can be used in creating a picture. A user should be able to place a shape on a canvas and drag it around or even enlarge it to create a desired picture.
I tried overriding the paintComponent()
of a JPanel
to achieve this but realize that the Jpanels shape remains a square so when you have a circle you can still drag it even if u are not necessarily touching it as it is within a square and also having difficulty drawing the triangle
What libraries would you suggest?
The Shape interface and derived classes, such as Path2D, Ellipse2D and Rectangle2D, will help you here, since all classes derived from it must have a
contains(Point p)
method that you can use.For example:
I'll let you figure out rotation and re-sizing.