当前位置: 代码迷 >> Java相关 >> JPanel显示不了背景图片,求助啊!
  详细解决方案

JPanel显示不了背景图片,求助啊!

热度:267   发布时间:2011-03-03 12:10:01.0
JPanel显示不了背景图片,求助啊!
代码贴上:
package memo;

import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;

class MemoFrame extends JFrame{
    JTextArea displayArea;
    ImageIcon img;
    Image image;
    JPanel backPanel;
    Container c = new Container();
    private static final long serialVersionUID = 4785452373598819719L;
    public MemoFrame(){
        super();
        displayArea = new JTextArea(null,20,30);
        img = new ImageIcon("back.jpg");
        image =img.getImage();
        backPanel = new JPanel(){
            private static final long serialVersionUID = 1234452373598819719L;
            public void paintComponents(Graphics g){
                g.drawImage(image, 0, 0, this);
                super.paintComponent(g);
            }
        };
        this.setSize(400,300);
        backPanel.setSize(400,300);
        displayArea.setOpaque(false);
        displayArea.setEditable(false);
        backPanel.add(displayArea);
        c = this.getContentPane();
        c.add( backPanel );
        setUndecorated(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);        
    }
}

package memo;

public class MemoDemo {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO 自动生成方法存根
        MemoFrame demo = new MemoFrame();
        demo.setVisible(true);

    }

}
哪位大侠帮帮忙啊!
搜索更多相关的解决方案: 背景图片  super  null  long  

----------------解决方案--------------------------------------------------------