熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

Java全屏帶分辨率設置

2022-06-13   來源: Java核心技術 

  Java代碼

  import javaawtColor;

  import javaawtDisplayMode;

  import javaawtFont;

  import javaawtGraphics;

  import javaxswingJFrame;

  public class FullScreenTest extends JFrame {

  public static void main(String[] args) {

  DisplayMode displayMode;

  if (argslength == ) {

  displayMode = new DisplayMode(

  IntegerparseInt(args[])

  IntegerparseInt(args[])

  IntegerparseInt(args[])

  DisplayModeREFRESH_RATE_UNKNOWN);

  }

  else {

  displayMode = new DisplayMode(

  DisplayModeREFRESH_RATE_UNKNOWN);

  }

  FullScreenTest test = new FullScreenTest();

  testrun(displayMode);

  }

  private static final long DEMO_TIME = ;

  public void run(DisplayMode displayMode) {

  setBackground(Colorblue);

  setForeground(Colorwhite);

  setFont(new Font(Dialog FontPLAIN ));

  SimpleScreenManager screen = new SimpleScreenManager();

  try {

  screensetFullScreen(displayMode this);

  try {

  Threadsleep(DEMO_TIME);

  }

  catch (InterruptedException ex) { }

  }

  finally {

  screenrestoreScreen();

  }

  }

  public void paint(Graphics g) {

  gdrawString(Hello World! );

  }

  }

  Java代碼

  import javaawtDisplayMode;

  import javaawtGraphicsDevice;

  import javaawtGraphicsEnvironment;

  import javaawtWindow;

  import javaxswingJFrame;

  /**

  * The SimpleScreenManager class manages initializing and displaying full screen

  * graphics modes

  */

  public class SimpleScreenManager {

  private GraphicsDevice device;

  /**

  * Creates a new SimpleScreenManager object

  */

  public SimpleScreenManager() {

  GraphicsEnvironment environment = GraphicsEnvironment

  getLocalGraphicsEnvironment();

  device = environmentgetDefaultScreenDevice();

  }

  /**

  * Enters full screen mode and changes the display mode

  */

  public void setFullScreen(DisplayMode displayMode JFrame window) {

  windowsetUndecorated(true);

  windowsetResizable(false);

  devicesetFullScreenWindow(window);

  if (displayMode != null && deviceisDisplayChangeSupported()) {

  try {

  devicesetDisplayMode(displayMode);

  } catch (IllegalArgumentException ex) {

  // ignore illegal mode for this device

  }

  }

  }

  /**

  * Returns the window currently used in full screen mode

  */

  public Window getFullScreenWindow() {

  return devicegetFullScreenWindow();

  }

  /**

  * Restores the screens display mode

  */

  public void restoreScreen() {

  Window window = devicegetFullScreenWindow();

  if (window != null) {

  windowdispose();

  }

  devicesetFullScreenWindow(null);

  }

  }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26128.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.