package window; import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JPanel; @SuppressWarnings("serial") public class BackgroundPanel extends JPanel { private Image backgroundImage; public BackgroundPanel() { ImageIcon icon = new ImageIcon("systemfile/bg.jpg"); if (icon.getImage() != null) { backgroundImage = icon.getImage(); } } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (backgroundImage != null) { g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this); } } }