Java by API/java.awt/GraphicsDevice

Материал из Java эксперт
Перейти к: навигация, поиск

GraphicsDevice: getAvailableAcceleratedMemory()

  
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.VolatileImage;
public class Main {
  public static void main(String[] argv) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (int i = 0; i < gs.length; i++) {
      VolatileImage im = gs[i].getDefaultConfiguration()
          .createCompatibleVolatileImage(1, 1);
      int bytes = gs[i].getAvailableAcceleratedMemory();
      if (bytes < 0) {
        System.out.println("Amount of memory is unlimited");
      }
      im.flush();
    }
  }
}





GraphicsDevice: getConfigurations()

 
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
public class MainClass {
  public static void main(String[] args) {
    GraphicsEnvironment ge;
    ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle vBounds = new Rectangle();
    GraphicsDevice[] gdArray = ge.getScreenDevices();
    for (int i = 0; i < gdArray.length; i++) {
      GraphicsDevice gd = gdArray[i];
      GraphicsConfiguration[] gcArray = gd.getConfigurations();
      for (int j = 0; j < gcArray.length; j++)
        vBounds = vBounds.union(gcArray[j].getBounds());
    }
    Point origin = vBounds.getLocation();
    System.out.println("Virtual x = " + origin.x);
    System.out.println("Virtual y = " + origin.y);
    Dimension size = vBounds.getSize();
    System.out.println("Virtual width = " + size.width);
    System.out.println("Virtual height = " + size.height);
  }
}





GraphicsDevice: getIDstring()

 
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());
  }
}





GraphicsDevice: isFullScreenSupported()

  
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Main extends Window {
  private BufferedImage pic;
  public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice screen = ge.getDefaultScreenDevice();
    if (!screen.isFullScreenSupported()) {
      System.out.println("Full screen mode not supported");
      System.exit(1);
    }
    try {
      BufferedImage loadedpic = ImageIO.read(new File("your.jpg"));
      screen.setFullScreenWindow(new Main (loadedpic));
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
  }
  public Main (BufferedImage pic) {
    super(new Frame());
    this.pic = pic;
    addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        System.exit(0);
      }
    });
  }
  public void paint(Graphics g) {
    g.drawImage(pic, 0, 0, getWidth(), getHeight(), this);
  }
}





GraphicsDevice: setFullScreenWindow(Window w)

  
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Main extends Window {
  private BufferedImage pic;
  public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice screen = ge.getDefaultScreenDevice();
    if (!screen.isFullScreenSupported()) {
      System.out.println("Full screen mode not supported");
      System.exit(1);
    }
    try {
      BufferedImage loadedpic = ImageIO.read(new File("your.jpg"));
      screen.setFullScreenWindow(new Main (loadedpic));
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
  }
  public Main (BufferedImage pic) {
    super(new Frame());
    this.pic = pic;
    addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        System.exit(0);
      }
    });
  }
  public void paint(Graphics g) {
    g.drawImage(pic, 0, 0, getWidth(), getHeight(), this);
  }
}