This section provides a tutorial example on how to use java.awt.Toolkit class to obtain the default Toolkit object, which also can provide information about the default graphics environment, the local screen.
java.awt.Toolkit is an AWT class acting as a base class for all implementations
of AWT. This class also offers a static method, getDetaulToolkit(), to return
a Toolkit object representing the default implementation of AWT.
You can use this default toolkit object to get information of the default graphics
device, the local screen. For example, you can find out the size and resolution
of the local screen.
To show you how to use the getDefaultToolkit() method,
I wrote the following sample program:
/**
* DefaultToolkit.java
* Copyright (c) 2002 by Dr. Herong Yang, http://www.herongyang.com/
*/
import java.awt.*;
import javax.swing.*;
public class DefaultToolkit {
public static void main(String[] a) {
Toolkit t = Toolkit.getDefaultToolkit();
Dimension d = t.getScreenSize();
System.out.println("Screen size: "+d.width+", "+d.height);
System.out.println("Screen resolution: "+t.getScreenResolution());
}
}
Output:
Screen size: 1024, 768
Screen resolution: 96
Comparing the output of DefaultToolkit.java with LocalGraphicsEnvironment,
the toolkit screen size doesn't match the environment window bounds.
I don't know why. I also don't know how to read the screen resolution value.
Is it 96 DPI (Dots Per Inch)?
Sample programs listed in this section have been tested with JDK 1.3.1, 1.4.1, 1.5.0 and 1.6.0.