Swing offers a number of utilities that are used internally within swing components, and the Swingutilities class is one of them. It provides a number of methods involving computing, transformation, access control, layout, etc., which have been widely used in various swing components. Of course, we can also apply it to our own program.
Here's a look at one of these practical features.
(1) Conversion method
MouseEvent convertmouseevent (Component source, MouseEvent ourceevent, Component destination)
Converts a mouse event from one component to another.
Point Convertpoint (Component source, int x, int y, Component estination)
Point Convertpoint (Component source, point Apoint, Component destination)
Converts the point coordinates on one component to a coordinate point on another component.
void Convertpointfromscreen (point P, Component c)
Converts a screen twilight coordinate point into a component's coordinate point.
void Convertpointtoscreen (point P, omponent c)
Converts a coordinate point on a component to a screen twilight coordinate.
Rectangle Convertrectangle (Component source, Rectangle Arectangle, Component destination)
Converts the rectangular coordinates on one component to the rectangular coordinates on another component.
(2) Calculation method
Rectangle[] Computedifference (Rectangle r1,rectangle R2)
Rectangle computeintersection (int x, int y, int width, int height, Rectangle dest)
Rectangle computeunion (int x, int y, int width, int height, Rectangle dest)
int Computestringwidth (fontmetrics FM, String str)
Boolean Isrectanglecontainingrectangle (Rectangle A, Rectangle b)
These methods compute the difference set, intersection, and set of two rectangles, and also determine whether a rectangle includes another rectangle and compute the pixel width of a string.
(3) mouse button information
Boolean Isleftmousebutton (MouseEvent anevent)
Boolean Ismiddlemousebutton (MouseEvent anevent)
Boolean Isrightmousebutton (MouseEvent anevent)
Determines which mouse button is pressed with the given mouse event.