java应用分辨率排版,在JAVA中,使用setDisplayMode为全屏应用程序更改分辨率

我是JAVA语言的初学者,正在尝试学习如何创建全屏应用程序。

我正在尝试创建一个简单的应用程序,该应用程序在运行时将显示一个带有蓝色背景的全屏,并在屏幕中央显示一条简单的文本行(起始位置为400x300)。应用程序的分辨率设置为800x600。

我在运行OSX

Lion的MacbookAir上运行代码,屏幕分辨率为1440x900。问题是,尽管像我预期的那样获得了蓝色背景,但文本仅出现在屏幕的左上方。当我增加其位置时,文本的位置将继续向右下移动,直到消失时达到1440x900以上。我猜想屏幕分辨率仍然设置为1440x900,而不是800x600。

这是我的主要课程:

import java.awt.*;

import javax.swing.JFrame;

public class bucky extends JFrame {

public static void main(String[] args){

DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);

bucky b = new bucky();

b.run(dm);

}

public void run(DisplayMode dm){

setBackground(Color.BLUE); // Setting background color

setForeground(Color.WHITE);

setFont(new Font("Arial", Font.PLAIN, 24));

//The Screen variable is going to be a screen object

Screen s = new Screen();

try{

s.setFullScreen(dm, this); //this refers to whatever object we are working on, ie 's'

try{

//Once it is set to full screen, and wait for 5 second

Thread.sleep(5000);

}catch(Exception ex){};

}

finally{

s.restoreScreen();

}

}

public void paint(Graphics g){

g.drawString("Test", 400, 300);

}

}

这是Screen类和Screen类中方法的构造函数,它将应用程序设置为全屏

private GraphicsDevice vc; // Gives an interface to graphics card/video card.

public Screen(){

//env is environment variable, containing all graphics manipulation objects

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

//When we get environment and getDegaultScreen Device, we get access to the entire monitor, not just a window

vc = env.getDefaultScreenDevice();

}

public void setFullScreen(DisplayMode dm, JFrame window){

window.setUndecorated(true);

window.setResizable(false);

vc.setFullScreenWindow(window);

if(dm != null && vc.isDisplayChangeSupported()) {

try{

vc.setDisplayMode(dm);

}catch(Exception ex){}

}

}

如果有人可以指出为什么分辨率设置不正确,将不胜感激。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值