Practiced with Video training for Game Development (up to 5th course). I typed the code which has to create fullscreen window , set background and foreground color, and finally output message. The problem is with background color, it does not switch to required one (to RED as in code example). Foreground color - displays as it is set within run() - method.
Would you please suggest where to look for the problem.
attached main code (class JGD3Screen) and class for screen functions (class Screen)
[highligh=Java]
import java.awt.*;
import javax.swing.JFrame;
public class JGD3Screen extends JFrame {
public static void main(String[] args){
DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
JGD3Screen b = new JGD3Screen();
b.run(dm);
}
public void run(DisplayMode dm){
setBackground(Color.RED);
setForeground(Color.WHITE);
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();
}
}
public void paint(Graphics g){
g.drawString("Test message ", 200, 200);
}
}
[/highlight]
Class Screen()
import java.awt.*; import javax.swing.JFrame; public class Screen { private GraphicsDevice vc; //interface to video card //creating constructor public Screen(){ // env - an object to work with graphics environment GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); vc = env.getDefaultScreenDevice(); } //Method that changes to full screen view of the screen 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){} } } //method public Window getFullScreenWindow(){ return vc.getFullScreenWindow(); } //method to restoring screen to normal public void restoreScreen(){ Window w = vc.getFullScreenWindow(); if (w != null){ w.dispose(); } vc.setFullScreenWindow(null); } }