ImageIcon image = new ImageIcon("5.gif");
...
ImagePanel panel = new ImagePanel(new BorderLayout(),image);
...class ImagePanel extends JPanel {
  private ImageIcon bg;
  public ImagePanel(LayoutManager layout,ImageIcon icon) {
    super(layout);
    bg = icon;
  }
  public void paintComponent(Graphics g)
  {
    super.paintComponent(g);
    Image img = bg.getImage();
    g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
  }
}