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:

 * Copyright (c) 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());


herong> java 

Screen size: 1024, 640
Screen resolution: 120

Comparing the output of with, 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

 About This Book

 JDK (Java Development Kit)

 Introduction of Java Swing Package

Graphics Environment of the Local System

 java.awt.GraphicsEnvironment - Graphics Environment Class

java.awt.Toolkit - AWT Base Class

 Testing Screen Resolution

 JFrame - Main Frame Class

 JLabel - Swing Label Class

 JButton - Swing Button 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

 LookAndFeel and UIManager

 Option Dialog Boxes

 JEditorPane - The Editor Pane Class

 SwingWorker - The Background Task Worker

 AWT (Abstract Windows Toolkit)

 Integration with Desktop System

 Outdated Tutorials


 Full Version in PDF/EPUB