Java by API/java.awt/GraphicsEnvironment

Материал из Java эксперт
Версия от 14:23, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

GraphicsEnvironment: getAllFonts()

import java.awt.Font;
import java.awt.GraphicsEnvironment;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Font[] fonts  = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for (int i = 0; i < fonts.length; i++) {
      System.out.print(fonts[i].getFontName() + " : ");
      System.out.print(fonts[i].getFamily() + " : ");
      System.out.print(fonts[i].getName());
      System.out.println();
    }
  }
}





GraphicsEnvironment: getAvailableFontFamilyNames()

/*
 * Output:
Fonts available on this platform: 
Agency FB
Arial
Arial Black
Arial Narrow
Arial Rounded MT Bold
Arial-SM
Blackadder ITC
Bodoni MT
Bodoni MT Black
Bodoni MT Condensed
Book Antiqua
Bookman Old Style
Bookshelf Symbol 7
Bradley Hand ITC
Calisto MT
Castellar
Century Gothic
Century Schoolbook
Comic Sans MS
Copperplate Gothic Bold
Copperplate Gothic Light
Courier New
.....
..... 
 * */
import java.awt.GraphicsEnvironment;
public class MainClass {
  public static void main(String[] args) {
    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontnames = e.getAvailableFontFamilyNames();
    System.out.println("\nFonts available on this platform: ");
    for (int i = 0; i < fontnames.length; i++)
      System.out.println(fontnames[i]);
    return;
  }
}





GraphicsEnvironment: getCenterPoint()

/*
 * Output: 
 * java.awt.Point[x=640,y=498]
 * */
import java.awt.GraphicsEnvironment;
import java.awt.Point;
public class MainClass {
  public static void main(String[] args) {
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment()
        .getCenterPoint();
    System.out.println(center);
  }
}





GraphicsEnvironment: getDefaultScreenDevice()

/*
  Default screen device: \Display0
  Configuration 1
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 2
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 3
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 4
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 5
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 6
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0*/
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
public class MainClass {
  public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
    GraphicsConfiguration[] configurations = defaultScreen.getConfigurations();
    System.out.println("Default screen device: " + defaultScreen.getIDstring());
    for (int i = 0; i < configurations.length; i++) {
      System.out.println("  Configuration " + (i + 1));
      System.out.println("  " + configurations[i].getColorModel());
    }
  }
}





GraphicsEnvironment: getLocalGraphicsEnvironment()

/*
  Default screen device: \Display0
  Configuration 1
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 2
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 3
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 4
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 5
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
  Configuration 6
  DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0*/
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
public class MainClass {
  public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
    GraphicsConfiguration[] configurations = defaultScreen.getConfigurations();
    System.out.println("Default screen device: " + defaultScreen.getIDstring());
    for (int i = 0; i < configurations.length; i++) {
      System.out.println("  Configuration " + (i + 1));
      System.out.println("  " + configurations[i].getColorModel());
    }
  }
}





GraphicsEnvironment: getScreenDevices()

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
public class MainClass {
  public static void main(String[] a) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screenDevices = ge.getScreenDevices();
    for (int i = 0; i < screenDevices.length; i++)
      System.out.println(screenDevices[i].getIDstring());
  }
}