Java 如何在应用程序运行时调用setUnderatted()?
嗨,我在编程方面不是很专业,所以我来这里是想问我如何才能做到这一点 问题:点击全屏模式后,客户端游戏正在运行。我希望它调用setUndecorated,但不能在框架已可见时调用 我意识到我需要创建一个新的框架,但我不确定如何转移一切,我已经尝试了自己,我得到的是一个新框架的空白白色屏幕 这是我的密码:Java 如何在应用程序运行时调用setUnderatted()?,java,swing,jframe,Java,Swing,Jframe,嗨,我在编程方面不是很专业,所以我来这里是想问我如何才能做到这一点 问题:点击全屏模式后,客户端游戏正在运行。我希望它调用setUndecorated,但不能在框架已可见时调用 我意识到我需要创建一个新的框架,但我不确定如何转移一切,我已经尝试了自己,我得到的是一个新框架的空白白色屏幕 这是我的密码: public Jframe(String args[]) { super(); try { sign.signlink.startpriv(InetAddress.
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、 e 然而,正如ghostbust555所指出的,有一种更好的方法 这是答案所指的SetFullScreen窗口:
public void goFullScreen() {
GraphicsDevice myDevice =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
// wrap in try because we don't want to lock the app in fullscreen mode
try {
myDevice.setFullScreenWindow(myFrame);
// do your stuff
...
} finally {
myDevice.setFullScreenWindow(null);
}
}
myFrame.setVisiblefalse;myFrame.setUndercoratedTrue;myFrame.setVisibletrue;这是行不通的;它仍然抛出错误。
public void goFullScreen() {
GraphicsDevice myDevice =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
// wrap in try because we don't want to lock the app in fullscreen mode
try {
myDevice.setFullScreenWindow(myFrame);
// do your stuff
...
} finally {
myDevice.setFullScreenWindow(null);
}
}