java

位置:IT落伍者 >> java >> 浏览文章

Java全屏带分辨率设置


发布日期:2018年06月26日
 
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);

}

}

               

上一篇:用Java实现断点续传(HTTP)

下一篇:《深入理解Java虚拟机》笔记