Using a JPanel extension class to set a background
问题 In my Main I want to create a JFrame , then I want to create a BackgroundPanel and I want to add this one in the JFrame . This is Main class: public class Main { public static void main(String args[]) { Frame frame = new Frame(); BackgroundPanel back = new BackgroundPanel(); frame.getContentPane().add(back); frame.setSize(400, 287); frame.setVisible(true); } } This is BackgroundPanel class: import java.awt.Graphics; import java.awt.Image; import java.awt.MediaTracker; import java.awt.Toolkit;