How to select a component?

1) How do we select a component? For example, we want to be able to draw multiple lines or rectangles and be able to select one of them or multiple with a mouse click. How can the user tell what one he selected?2) When you select a component, how do we add handles to it?
[285 byte] By [igcoola] at [2007-10-2 12:39:14]
# 1

> 1) How do we select a component? For example, we want

> to be able to draw multiple lines or rectangles and

> be able to select one of them or multiple with a

> mouse click. How can the user tell what one he

> selected?

In normal Swing, line != component. Same for rectangle. Either (a) Implement components which draw themselves as lines or rectangles or (b) manually handle component selection etc.

(b) will probably be far less painful. As for visual feedback, well, that all depends on your preferences/requirements. You could change their color, draw dashed lines, whatever. Most of the times this would come down to

- Associate user input with an object (e.g., translate mouse over(x, y) to mous over aComponent)

- Associate user input with a state of the object (e.g., translate mouse clicked over aComponent to aComponent is selected)

- Draw associated feedback (e.g., draw a dashed line along aComponents bounding rectangle)

If you want more help, try being more specific about what your application is supposed to do.

> 2) When you select a component, how do we add handles

> to it?

Depends. What kind of handles? Visual handles? Callback handles? Door handles ;) ?

DaanSa at 2007-7-13 9:42:12 > top of Java-index,Security,Event Handling...