import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class MyJPanel extends JPanel {
		                @Override
		            //这个方法是用来画Panel组件的
		            public  void paint(Graphics g) {
		                    try {	
		                    	 File file = new File("e:\\a.png");
		                       // System.out.println(file.length());

		                    g.setColor(Color.green);   //（0，0）位置绘制一个20*20的绿色方块
		                    g.fillRect(0, 0, 20, 20);

		                        BufferedImage img=ImageIO.read(file);
		                        //BufferedImage img = ImageIO.read(new File(this.getClass().getResource("Winter.jpg").getPath()));
		                        g.drawImage(img, 0, 0, 800, 600, null);
		                        
		                        
		                    } catch (IOException e) {
		                        e.printStackTrace();
		                    }
		                }
		            }