如何在应用程序运行时调用 setUndecorated()?
嗨,我在编程方面不是那么专业,所以我来这里是为了问我如何才能做到这一点。
问题:一旦单击全屏模式,客户端游戏就会运行,我希望它调用 setUndecorated(),但在框架已经可见时无法调用。
我意识到我需要创建一个新框架,但我不确定如何将所有内容转移过来,我自己尝试过,我得到的只是新框架的空白屏幕。
这是我的代码:
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();
}
我希望你们中的任何人都可以帮助我,非常感谢!
Hi I'm not such a professional at programming so i come here to ask how i can make this possible.
Issue: Client game is running once fullscreen mode clicked i want it to call setUndecorated() but cant while the frame is already visible.
I realized that i would need to create a new frame but im unsure how to transfer everything over, i have tried myself and all i get is a blank white screen of the new frame.
Here is my code:
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();
}
I hope any of you can help i really appreciate thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这是为了游戏,那么您很可能不想要这个。你应该看看
http://download.oracle.com/javase/tutorial/extra/fullscreen /exclusivemode.html
If this is for a game then most likely you don't want this. You should take a look at
http://download.oracle.com/javase/tutorial/extra/fullscreen/exclusivemode.html
我可能会指出显而易见的事情,并促进错误的方法,但你不能先让它不可见,然后再让它可见吗?
ie
但是,正如“ghostbust555”指出的那样,有更好的方法。
这是答案所指的
setFullScreenWindow()
:I may be pointing out the obvious, as well as facilitating the wrong approach, but can't you just make it not visible then make it visible again?
i.e.
However, there is a better approach, as "ghostbust555" pointed out.
This is the
setFullScreenWindow()
that answer was referring to: