I have two class files:
Screen https://gist.github.com/3020101
JMain https://gist.github.com/3020107
I try to get it to work in full screen for 5 seconds and display the background (or, at the moment, even the foreground), but when I run it, it goes into full screen for 5 seconds, yay, but it's just empty light gray screen.
What am I doing wrong? In the end, I'm going to use the image for the background, and I want to make sure that I'm not scared somewhere.
Thanks guys!
Edit: when I add this to the end of my JMain class, the font color matches the foreground color, but the background is always black, no matter what color I change in the program.
public void paint(Graphics g) { g.drawString("This is gonna be awesome", 200, 200); }
code from github
import java.awt.*; import javax.swing.JFrame; public class JMain extends JFrame { private JFrame frame = new JFrame(); public static void main(String[] args) { DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN); JMain m = new JMain(); m.run(dm); } public void run(DisplayMode dm) { this.getContentPane().setBackground(Color.RED); frame.setForeground(Color.BLACK); frame.setFont(new Font("Arial", Font.PLAIN, 24)); Screen s = new Screen(); try { s.setFullScreen(dm, this); try { Thread.sleep(5000); } catch (Exception ex) { } } finally { s.restoreScreen(); } } }
and
import java.awt.*; import javax.swing.JFrame; public class Screen { private GraphicsDevice vc; public Screen() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); vc = env.getDefaultScreenDevice(); } public void setFullScreen(DisplayMode dm, JFrame window) { window.setUndecorated(true); window.setResizable(false); vc.setFullScreenWindow(window); if (dm != null && vc.isDisplayChangeSupported()) { try { vc.setDisplayMode(dm); } catch (Exception ex) { } } } public Window getFullScreenWindow() { return vc.getFullScreenWindow(); } public void restoreScreen() { Window w = vc.getFullScreenWindow(); if (w != null) { w.dispose(); } vc.setFullScreenWindow(null); } }