Draw pointable / pickable lines, etc, how to?



Hello,
I am wondering what is the best way to this common GUI task:

Draw some rectangles, lines, pies, etc (say, in a JPanel). Make sure
these things are "pointable" and "pickable": when mouse is moved over
it, we can press mouse key to "pick up" it and drag it around, etc.

Previously in some early school homework projects, I just stored the
locations for each of them in an array. For example, for a line, I
stored its starting and ending (x, y) points. For a rectangle, I stored
its 4 corner points (x,y). In listener for mouse move (or click, drag)
in JPanel, I got the current mouse's position, and checked each item in
the above array to see if the mouse was in any of them. This worked ok
with not too many lines or rectangles. And it did not use too much
memory also since only several integers needed to be saved for each
line or rectangle, etc.

Any idea of better method? (in terms of efficiency, for example, we may
have 10000 rectangels and 50000 lines. And of course we need it for
real time when user moves the mouse around).

Thanks. :-)

.



Relevant Pages

  • Re: Draw pointable / pickable lines, etc, how to?
    ... Draw some rectangles, lines, pies, etc (say, in a JPanel). ... it, we can press mouse key to "pick up" it and drag it around, etc. ...
    (comp.lang.java.gui)
  • Re: How to handle mouse events in JPanel?
    ... The new kind of JPanel can handle Mouse Events so that I can click ... inside of it and create rectangles. ... and MouseInputHandler ... your drawing with the FlowLayout which comes with JPanel. ...
    (comp.lang.java.programmer)
  • jpanel export as pbm file
    ... I have a JPanel with some custom drawings on it like ... rectangles, circles etc. ...
    (comp.lang.java.gui)
  • jpanel export as pbm image
    ... I have a JPanel with some custom drawings on it like ... rectangles, circles etc. ...
    (comp.lang.java.programmer)
  • Re: catching Runtime Stack Overflow Exception
    ... it is caused by a Region containing too many rectangles. ... > the entire array is allocated on the stack. ... Arrays themselves are *always* reference types. ...
    (microsoft.public.dotnet.framework)