全屏Jframe演示应用程序具有怪异的滞后和帧速率问题
我最近开始学习如何使用 Jframe,这样我就可以制作实际的 GUI,因为没有人想要一个仅依赖于 cmd 的应用程序,因此在制作一个使用一点点东西的基本演示应用程序时,我学会了如何使用 GraphicsDevice 和 GraphicsEnvironment 进行全屏显示我还将显示模式设置为 2560 x 1440、32 位深度和 60 fps。但由于某种原因,每当应用程序处于全屏状态时,在窗口打开大约 1 到 2 秒后,它就会出现奇怪的卡顿和短暂的 fps 下降。我尝试使用显示模式更改分辨率、帧速率和位深度,但除非退出全屏,否则什么都不会改变。我该怎么办? (提前抱歉,我只是在玩弄乱七八糟的代码。不完全是一个专业程序员,只是一个爱好)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Gui {
public static void main(String[] args) {
JFrame f = new JFrame("Demo Thingy");
GraphicsEnvironment graphics = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = graphics.getDefaultScreenDevice();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField tf = new JTextField();
tf.setBounds(50, 50, 150, 20);
JButton b = new JButton("Click to exit");
JButton b2 = new JButton("Click here to fullscreen/exit fullscreen");
b2.setBounds(600, 100, 250, 30);
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (device.getFullScreenWindow() == f) {
device.setFullScreenWindow(null);
f.setSize(1000, 1000);
f.setVisible(true);
} else if (device.getFullScreenWindow() == null) {
device.setFullScreenWindow(f);
f.setVisible(true);
}
}
});
b.setBounds(50, 100, 250, 30);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
f.add(b);
f.add(b2);
f.add(tf);
f.setResizable(false);
f.setUndecorated(true);
device.setFullScreenWindow(f);
device.setDisplayMode(new DisplayMode(2560, 1440, 16, 60));
f.setVisible(true);
}
}
I started recently learning how to use Jframe so I can make actual GUIs because no one wants an application that relies solely on cmd, so while making a basic demo app that uses a little bit of everything, I learned how to fullscreen using GraphicsDevice and GraphicsEnvironment and I also set the display mode to 2560 x 1440, 32 bit depth, and 60 fps. But for some reason, whenever the application is in fullscreen, it has these weird stutters and short fps drops after the window is open for around 1 to 2 seconds. I tried changing the resolution, framerate, and bit depth with display mode, but nothing changes unless I exit fullscreen. What do I do? (Sorry in advance, messy code that I was just playing around with. Not exactly a professional programmer, just a hobby thing)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Gui {
public static void main(String[] args) {
JFrame f = new JFrame("Demo Thingy");
GraphicsEnvironment graphics = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = graphics.getDefaultScreenDevice();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField tf = new JTextField();
tf.setBounds(50, 50, 150, 20);
JButton b = new JButton("Click to exit");
JButton b2 = new JButton("Click here to fullscreen/exit fullscreen");
b2.setBounds(600, 100, 250, 30);
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (device.getFullScreenWindow() == f) {
device.setFullScreenWindow(null);
f.setSize(1000, 1000);
f.setVisible(true);
} else if (device.getFullScreenWindow() == null) {
device.setFullScreenWindow(f);
f.setVisible(true);
}
}
});
b.setBounds(50, 100, 250, 30);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
f.add(b);
f.add(b2);
f.add(tf);
f.setResizable(false);
f.setUndecorated(true);
device.setFullScreenWindow(f);
device.setDisplayMode(new DisplayMode(2560, 1440, 16, 60));
f.setVisible(true);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论