Java全屏带分辨率设置

Java全屏带分辨率设置,第1张

Java代码

唤乱喊import java awt Color

import java awt DisplayMode

import java awt Font

import java awt Graphics

import javax swing JFrame

public class FullScreenTest extends JFrame {

public static void main(String[] args) {

DisplayMode displayMode

if (args length == ) {

displayMode = new DisplayMode(

Integer parseInt(args[ ])

Integer parseInt(args[ ])

Integer parseInt(args[ ])

DisplayMode REFRESH_RATE_UNKNOWN)

}

 陪氏 else {

displayMode = new DisplayMode(

DisplayMode REFRESH_RATE_UNKNOWN)

}

FullScreenTest test = new FullScreenTest()

test run(displayMode)

}

private static final long DEMO_TIME =

public void run(DisplayMode displayMode) {

setBackground(Color blue)

setForeground(Color white)

setFont(new Font( Dialog Font PLAIN ))

SimpleScreenManager screen = new SimpleScreenManager()

try {

screen setFullScreen(displayMode this)

try {

Thread sleep(DEMO_TIME)

}

catch (InterruptedException ex) { }

}

finally {

screen restoreScreen()

}

}

public void paint(Graphics g) {

g drawString( Hello World! )

}

}

Java代码

import java awt DisplayMode

import java awt GraphicsDevice

import java awt GraphicsEnvironment

import java awt Window

import javax swing JFrame

/**

* 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 = environment getDefaultScreenDevice()

 和野 }

/**

* Enters full screen mode and changes the display mode

*/

public void setFullScreen(DisplayMode displayMode JFrame window) {

window setUndecorated(true)

window setResizable(false)

device setFullScreenWindow(window)

if (displayMode != null &&device isDisplayChangeSupported()) {

try {

device setDisplayMode(displayMode)

} catch (IllegalArgumentException ex) {

// ignore illegal mode for this device

}

}

}

/**

* Returns the window currently used in full screen mode

*/

public Window getFullScreenWindow() {

return device getFullScreenWindow()

}

/**

* Restores the screen s display mode

*/

public void restoreScreen() {

Window window = device getFullScreenWindow()

if (window != null) {

window dispose()

}

device setFullScreenWindow(null)

}

lishixinzhi/Article/program/Java/hx/201311/26128

创建一个JFrame ,设置成undecorated,设置bounds为凳梁数屏幕大小

//import 如下:

import java.awt.Dimension

import java.awt.Rectangle

import java.awt.Toolkit

import javax.swing.JFrame

代码如下:

JFrame frame = new JFrame()

frame.setUndecorated(true)

/枣首/ 取得屏渣派幕大小

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize()

Rectangle bounds = new Rectangle( screenSize )

frame.setBounds( bounds )

frame.setVisibale(true)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12228552.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存