1、final ImageIcon bgImageIcon = new ImageIcon(MyJFrame.class.get潮贾篡绐ClassLoader().getResource("com/zjc/Desert.jpg"));final Image image = bgImageIcon.getImage();//设置背景图片的路径地址
2、JFrame frame = new JFrame(&孥恶膈茯quot;this is background pic test") { private static final long serialVersionUID = 1L; public void paint(Graphics g) { g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null); }};//进行图重绘
3、frame.setSize(300, 400);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);//设置frame对象显示出来
4、运行后效果如下图: