How to make vector line selectable?

I'm making a project for college, where I have to make my own primitive vector editor, and I have two questions:

  1. Is it right to make vector line object by saving it's start point coordinates, end point coordinates, color and width of points, which it will consist of? Point is also my class, which is drawn on JPanel.
  2. If it is right, how can I make this line selectable? The only thing I can think of is to check mouse coordinates to be inside of line width.

I also have a restriction not to use any standard functions for drawing lines, splines, etc.

Answers


  1. Yes that's right. Or you could represent it in polar coordinates
  2. the best thing to do is actually turn your line into an 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.

Need Your Help

Get Node.js to get user's input from a HTML text field?

javascript ajax node.js

I've basically been trying to make a simple game where the user can submit their high-score to a Node.js server. I'm just trying to do something very simple but can't seem to find much to help me o...