I am trying to get a simple fullscreen window for a game I am making. I want to have the code that makes the window go fullscreen in a different class to my main class (called FullScreenWindow), but have the main class activate the fullscreen mode. The code that makes the window fullscreen in in the 'Screen' class.
Here is the code for the Screen class:
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; import javax.swing.JLabel; @SuppressWarnings("serial") public class Screen extends JFrame{ public Screen( String title ) { super(title); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); FullScreenWindow frame = new FullScreenWindow(); frame.setVisible(true); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); setUndecorated(true); if (gd.isFullScreenSupported()) { setUndecorated(true); gd.setFullScreenWindow(this); } else { System.err.println("Full screen not supported"); setSize(100, 100); // just something to let you see the window setVisible(true); } getContentPane().add(new JLabel("Test Fullscreen"), BorderLayout.NORTH); setBackground(Color.BLUE); setForeground(Color.WHITE); setFont(new Font("Arial", Font.PLAIN, 24)); drawString("This is cool", 200, 200); if(isVisible() == true){ try{ try { Thread.sleep(5000); } catch (Exception ex) { ex.printStackTrace(); } }finally{ Screen.this.setVisible(false); System.exit(0); } } } private void drawString(String string, int i, int j) { // TODO Auto-generated method stub } }
Here is the code in my FullScreenWindow class (my main class)
import java.awt.*; import javax.swing.*; @SuppressWarnings("serial") public class FullScreenWindow extends JFrame { public static void main(String[] args){ } }
I hope you can help.