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();
    }
     
}

try

Image bg = new ImageIO(new File ("stewie.jpg"));

To be honest I dont know how to do the IO stuff yet, but my program is never calling the paint method for some reason and I cant figure it out. I put a print statement in the paint method and it was never printed

try changing the name to paintComponent, and call repaint(); from where you want the program to run it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.