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
 */
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:

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

Sample programs listed in this section have been tested with JDK 1.3.1 to 1.8.0.

Last update: 2014.

Table of Contents

 About This Book

 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

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field 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

 References

 PDF Printing Version