java.awt.GraphicsEnvironment - Graphics Environment Class

This section describes java.awt.GraphicsEnvironment - Graphics Environment Class. You can use this class to get a lot of information about your local graphics device, which is really your computer screen.

java.awt.GraphicsEnvironment is an AWT class representing graphics environment that are accessible by the local operating system. This class also offers a static method, getLocalGraphicsEnvironment(), to return an object representing the local default graphics environment.

You can use this local graphics environment object to get a lot of information about your local system. For example, you can find out what text fonts are available, and what is maximum size of the graphical drawing area on the screen.

To show you how to use the getLocalGraphicsEnvironment() method, I wrote the following sample program:

/* LocalGraphicsEnvironment.java
 * Copyright (c) 1997-2024 HerongYang.com. All Rights Reserved.
 */
import java.awt.*;
public class LocalGraphicsEnvironment {
   public static void main(String[] a) {
      GraphicsEnvironment e 
         = GraphicsEnvironment.getLocalGraphicsEnvironment();
      String n[] = e.getAvailableFontFamilyNames();
      System.out.println("Font families:");
      for (int i=0; i<n.length; i++) {
         System.out.println("   "+n[i]);
      }
      Point p = e.getCenterPoint();
      System.out.println("Window center point: "+p.x+", "+p.y);
      Rectangle r = e.getMaximumWindowBounds();
      System.out.println("Maximum window bounds: "+r.x+", "+r.y
         +", "+r.width+", "+r.height);
      GraphicsDevice g = e.getDefaultScreenDevice();
      System.out.println("Device ID: "+g.getIDstring());
   }
}

Output:

herong> java LocalGraphicsEnvironment.java

Font families:
   Albertus Extra Bold
   Albertus Medium
   Antique Olive
   Arial
   Arial Black
   Arial Narrow
   ......
Window center point: 512, 296
Maximum window bounds: 0, 0, 1024, 592
Device ID: \Display0

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

 Archived Tutorials

 References

 Full Version in PDF/EPUB