Java Reference
In-Depth Information
// Sketching application
import javax.swing.*;
import java.awt.*;
public class Sketcher {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createWindow();
}
});
}
public static void createWindow(){
window = new SketcherFrame("Sketcher");
// Create the app
window
Toolkit theKit = window.getToolkit();
// Get the window
toolkit
Dimension wndSize = theKit.getScreenSize();
// Get screen size
// Set the position to screen center & size to half screen size
aWindow.setSize(wndSize.width/2, wndSize.height/2);
// Set
window size
aWindow.setLocationRelativeTo(null);
// Center
window
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
private static SketcherFrame window;
// The application
window
}
Directory
"
Sketcher 1
"
Save this file as
Sketcher.java
in the
Sketcher
directory. If you compile and run
Sketcher
, you should
see the window shown in
Figure 17-36
.