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 w开发者_开发百科hite 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!
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
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.
myFrame.setVisible(false);
myFrame.setUndecorated(true);
myFrame.setVisible(true);
However, there is a better approach, as "ghostbust555" pointed out.
This is the setFullScreenWindow()
that answer was referring to:
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);
}
}
精彩评论