/*** Set the background image of the form * @ author gao */package com. gao; import java. awt. graphics; import java. awt. image; import javax. swing. imageIcon; import javax. swing. JFrame; import javax. swing. JPanel; public class BackgroundDemo extends JFrame {private Image image; private static final long serialVersionUID =-1588458291133087637L; public BackgroundDemo () {this. setTitle ("set the background color of the form"); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); this. setBounds (0, 0,400,300); JPanel contentPane = new JPanel () {@ Override public void paint (Graphics g) {ImageIcon icon = new ImageIcon ("2.jpg"); image = icon. getImage (); g. drawImage (image, 0, 0, null); // TODO Auto-generated method stub}; this. add (contentPane); this. setVisible (true);} public static void main (String [] args) {BackgroundDemo example = new BackgroundDemo ();}}