java jframe全屏_Java-将JFrame设置为全屏时,屏幕变黑

我试图在画布上绘制一些东西,将其添加到JFrame,然后将此JFrame设置为“全屏”.我的问题是:在全屏模式下,我只会看到黑屏.

在屏幕变黑之前,我很快就能看到画布的粉红色背景.

直接在JFrame上绘制,然后将其设置为全屏,效果很好,我可以看到测试文本.我假设正确显示画布存在问题.

这是我的代码:

public class FullscreenTest extends Canvas {

private JFrame mainFrame;

public FullscreenTest(){

this.mainFrame = new JFrame();

JPanel contentPane = (JPanel) mainFrame.getContentPane();

contentPane.add(this);

}

public void run(DisplayMode dm){

setBackground(Color.PINK);

setForeground(Color.WHITE);

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

Screen s = new Screen();

s.setFullScreen(dm, this.mainFrame);

try {

Thread.sleep(5000);

} catch (InterruptedException exc) { exc.printStackTrace(); }

s.closeFullScreenWindow();

}

public void paint(Graphics g){

g.drawString("This is some testtext", 200, 200);

}

public static void main(String[] args){

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

FullscreenTest test = new FullscreenTest();

test.run(dm);

}

}

这是Screen.setFullScreen(DisplayMode dm,JFrame window)方法的作用:

//graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment()

// .getDefaultScreenDevice();

public void setFullScreen(DisplayMode dm, JFrame window){

window.setUndecorated(true);

window.setResizable(false);

graphicsDevice.setFullScreenWindow(window);

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

graphicsDevice.setDisplayMode(dm);

}

}

有谁知道为什么我无法全屏显示JFrame的内容?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值