Java Swing Tutorials - Herong's Tutorial Examples - v4.32, by Herong Yang
java.awt.Toolkit - AWT Base Class
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) 1997-2024 HerongYang.com. All Rights Reserved. */ import java.awt.*; 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:
herong> java DefaultToolkit.java Screen size: 1024, 640 Screen resolution: 120
Comparing the output of DefaultToolkit.java with LocalGraphicsEnvironment.java, 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 120 DPI (Dots Per Inch)?
Table of Contents
Introduction of Java Swing Package
►Graphics Environment of the Local System
java.awt.GraphicsEnvironment - Graphics Environment Class
►java.awt.Toolkit - AWT Base Class
JCheckBox - Swing Check Box Class
JRadioButton - Swing Radio Button Class
JTextField - Swing Text Field Class
JComboBox - Swing Combo Box Class
Menu Bar, Menus, Menu Items and Listeners
Creating Internal Frames inside the Main Frame
Layout of Components in a Container
JEditorPane - The Editor Pane Class
SwingWorker - The Background Task Worker
AWT (Abstract Windows Toolkit)