2011-09-13 22 views
0

嗨我不是在編程方面很專業,所以我來這裏問我如何能做到這一點。如何在應用程序運行時調用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(); 
    } 

我希望你們中的任何可以幫助我真的很感激的感謝!

回答

0

我可能會指出明顯的,以及促進錯誤的方法,但不能只是使其不可見,然後再次使其可見?

myFrame.setVisible(false); 
myFrame.setUndecorated(true); 
myFrame.setVisible(true); 

然而,有一個更好的辦法,如 「ghostbust555」 指出。

這是setFullScreenWindow()這個問題的答案是指:

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); 
    } 
} 
+0

myFrame.setVisible(假); myFrame.setUndecorated(true); myFrame.setVisible(true); 這是行不通的;它仍然會拋出錯誤。 – Coupon22

相關問題