I am trying to get a simple fullscreen window for a game I am making. I have the code in my Screen class (With no apparent errors). I need to know how to run the fullscreen code from my FullScreenWindow 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 { }