Java Swing Tutorial - Java GraphicsDevice .getAvailableAcceleratedMemory ()








Syntax

GraphicsDevice.getAvailableAcceleratedMemory() has the following syntax.

public int getAvailableAcceleratedMemory()

Example

In the following code shows how to use GraphicsDevice.getAvailableAcceleratedMemory() method.

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.VolatileImage;
//  w  ww  . j ava  2s . co m
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();
    }
  }
}

The code above generates the following result.