Reputation: 821
I'm making a project for college, where I have to make my own primitive vector editor, and I have two questions:
Point
is also my class, which is drawn on JPanel
.I also have a restriction not to use any standard functions for drawing lines, splines, etc.
Upvotes: 2
Views: 781
Reputation: 42040
Vector
if you have one with start
and end
Point
for do it if you want.You can have a method like that:
private static Shape generateVector(Point start, Point end)
In this method you can use one object of ´Area´ for build the vector, with Line2D
. Tree lines if you want an arrow.
Or you can use a GeneralPath
for build it.
For select a particular vector with the mouse, you can get the coordinates, with getX()
and getY()
on the MouseEvent
and ask in the shape object with method contains
and repaint with other color.
Good luck!
Upvotes: 0
Reputation: 57421
You can use Line2D Shape. To check selection you can gt stroked Shape from BasicStroke and check whether the stroked Shape contains clicked point.
Upvotes: 1
Reputation: 3412
To Point 1: You also need to save the direction of the vector.
To Point 2: There are some frameworks like GEF which do the job for you. Here you have to change your model. You need two classes: Point and Connection
Upvotes: 0
Reputation: 35096
Area
, which implements Shape
and thus contains, which is the method you want. Area
is a great abstraction because it can represent any shape but everything gets manipulated in the same way.Upvotes: 2