12.1. The Local Graphics Environment

A graphics environment is represented by an instance of java.awt.GraphicsEnvironment. You can get one of these objects representing the local computer using a handy factory method:

public static GraphicsEnvironment getLocalGraphicsEnvironment()

This method returns a GraphicsEnvironment for the local computer.

12.1.1. Font Information

A GraphicsEnvironment knows about fonts that are installed on a computer. There are three methods that provide information about the fonts in a particular environment:

public abstract Font[] getAllFonts()

This method returns every font in the system in an array.

public abstract String[] getAvailableFontFamilyNames()

This method returns an array of strings containing the family names of every available font. For more information about how fonts are named, refer back to Chapter 6.

public abstract String[] getAvailableFontFamilyNames(Locale l)

This method is the same as the previous method, but it returns the names for a particular Locale.

Chapter 6 has examples that show how to use these methods.

12.1.2. Finding Screen Devices

GraphicsEnvironment includes two methods for finding out about screen devices. These are represented by instances of java.awt.GraphicsDevice, which we'll discuss later in this chapter. The two methods are:

public abstract GraphicsDevice[] getScreenDevices()

This method returns an array containing all the screen devices accessible in this environment.

public abstract GraphicsDevice getDefaultScreenDevice() ...

Get Java 2D Graphics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.