java应用程序运行时如何调用setUnderatted()?
嗨,我不是编程方面的专业人士,所以我来这里是想问我如何才能做到这一点
问题:点击全屏模式后,客户端游戏正在运行。我希望它调用setUnderatted(),但不能在框架已可见时调用
我意识到我需要创建一个新的框架,但我不确定如何转移一切,我已经尝试了自己,我得到的只是一个新框架的空白白色屏幕
这是我的代码:
public Jframe(String args[]) {
super();
try {
sign.signlink.startpriv(InetAddress.getByName(server));
initUI();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void initUI() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBackground(Color.BLACK);
gamePanel = new JPanel();
gamePanel.setLayout(new BorderLayout());
gamePanel.add(this);
JMenu fileMenu = new JMenu("Menu");
String[] mainButtons = new String[] { "-", "Donate", "-", "Vote", "-", "Hiscores", "-", "Forums", "-", "Exit"};
for (String name : mainButtons) {
JMenuItem menuItem = new JMenuItem(name);
if (name.equalsIgnoreCase("-")) {
fileMenu.addSeparator();
} else {
menuItem.addActionListener(this);
fileMenu.add(menuItem);
}
}
JMenuBar menuBar = new JMenuBar();
JMenuBar jmenubar = new JMenuBar();
Jframe.frame.setMinimumSize(new Dimension(773, 556));
frame.add(jmenubar);
menuBar.add(fileMenu);
frame.getContentPane().add(menuBar, BorderLayout.NORTH);
frame.getContentPane().add(gamePanel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
frame.setResizable(true);
init();
} catch (Exception e) {
e.printStackTrace();
}
我希望你们中的任何人都能帮助我真的很感激谢谢
# 1 楼答案
我可能会指出显而易见的问题,也会助长错误的做法,但你不能让它不可见,然后再让它可见吗
即
然而,正如“ghostbust555”所指出的,有一种更好的方法
这就是答案所指的
setFullScreenWindow()
:# 2 楼答案
如果这是一个游戏,那么你很可能不想要这个。你应该看看 http://download.oracle.com/javase/tutorial/extra/fullscreen/exclusivemode.html