Java Reference
In-Depth Information
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createWindow();
}
});
}
}
TryWindow.java
Under Microsoft Windows, the program displays the window shown in
Figure 17-4
.
How It Works
The first
import
statement adds the
JFrame
class in the
javax.swing
package to the program. From now
on most of your programs use the components defined in this package. The second adds the
SwingUtil-
ities
class that you use in the
main()
method.
The code to create and display the application window is in the static
createWindow()
method. The
method
setBounds()
defines the size and position of the window; the first pair of arguments correspond
to the
x
and
y
coordinates of the top-left corner of the application window relative to the top-left corner
of the display screen, and the second pair of arguments specify the width and height of the window in
pixels. The screen coordinate system has the origin point, (0, 0), at the top-left corner of the screen, with
the positive
x
-axis running left to right and the positive
y
-axis from top to bottom. The positive
y
-axis in
screen coordinates is therefore in the opposite direction to that of the usual Cartesian coordinate system.
The coordinate system for screen coordinates is illustrated in
Figure 17-5
.