posted 17 years ago
The Points dest and mldst are the same. The convertPoint arguments are the same for each
one. All you need, so far, is mouse coordinates in the panel coordinate system. I included
the converted point (converted to the JFrame coordinate system) for illustration. It isn't
really useful in this app.
In response to your questions:
1 — in mousePressed Point p is the mouse position on the JPanel panel. We know this
because we added the MouseListener to panel so it must report coordinates in the panel
coordinate system. To place a circle at the mouse location we center a new Ellipse2D over
the mouse point obtained from the MouseEvent in mousePressed.
2 — the two points are in different coordinate systems: the MouseEvents are
reporting locations in the panel coordinate system, the converted point is in the JFrame
coordinate system. So the x and y values should differ by the difference in sizes of the
frame and the child component panel. This difference is the sum of the insets of all
parents of panel: JScrollPane, contentPane, JFrame. Console shows this when code is run.
3 — this is required by the compiler. Removing the final modifier results in this
compiler error:
The argument type is Component (superclass of JFrame); selected because Component is the
type required in the convertPoint method. This counts as an implicit cast. It could just
as easily have been JFrame, Frame or Window.
I don't know if there is a name for this use of final.
4 — I do not see any difference before/after scrolling left/right.