I am trying to load a background in full screen mode, but when i run my program the screen is just white. Can someone point me to the reason why?
import java.awt.*;
import javax.swing.*;
public class DrawComponents {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
GraphicsConfiguration gc = device.getDefaultConfiguration();
Image bg = new ImageIcon("stewie.jpg").getImage();
public void run(){
setFrame();
loadImages();
try{Thread.sleep(5000);}
catch(Exception e){}
System.exit(0);
}
public void setFrame(){
JFrame frame = new JFrame(gc);
frame.setUndecorated(true);
frame.setResizable(false);
frame.setIgnoreRepaint(true);
device.setFullScreenWindow(frame);
device.setDisplayMode(new DisplayMode(800, 600, 32, 0));
}
public void loadImages(){
bg = new ImageIcon("stewie.jpg").getImage();
}
public void paint(Graphics g) {
g.drawImage(bg, 400, 300, null);
}
public static void main(String[] args) {
DrawComponents drawComponents = new DrawComponents();
drawComponents.run();
}
}