you use Rectangle as a basic component In the
getContent method the Rectangle is used to store the [x, y, width, height]
information that is required for setting the location (x,y) and size (width,height) of
each JLabel added to the parent Container with null layout.
In the
addLabel method
We are still adding JLabel (as the basic) components but using a null layout which
requires that we specify the location/size for each child component.
setBounds is
one way to do this.
the difference is that in your code ...
here only Rectanle has method to call lines[j].intersects(seeker);
but JLabel did not have this method, In the code block for
mousePressed the Rectangle
seeker is used as an easy
way to
test if the mouse is on top of or close enough to any of the lines which connect
the components. By moving/centering the Rectangle
seeker under the
mousePressed location we can test for Rectangle/Line intersection. This will allow the user to select
any of the visible lines that connect the basic components. We are testing for
intersection between the single/movable Rectangle instance
seeker and each of the
visible connection lines.
If I use JLabel, how Can I find a method something like intersects to make sure this
line intersects with this JLabel instead of Rectangle?? This is a different question. To test if any line intersects a JLabel (or just about any
other Component) you can use the bounds of the JLabel for the test
Edit: Correct formatting.
[ April 30, 2007: Message edited by: Craig Wood ]