在网上找了好久,是了一些都没成功,希望高手详细解答。

解决方案 »

  1.   

    import java.awt.*; 
    import javax.swing.*; 
    public class Demo extends JFrame
       { 
          public Demo() {
          
        super("Title"); 
            NewPanel p = new NewPanel();
            this.getContentPane().add(p); //将面板添加到JFrame上11      
            this.setSize(510,298); //初始窗口的大小12      
            this.setLocationRelativeTo(null); //设置窗口居中13      
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
            this.setVisible(true); }
         
    public static void main(String[] args)
    {
       new Demo();     
    }
    class NewPanel extends JPanel
    {
       public NewPanel()
        {
        }
       public void paintComponent(Graphics g)
       {
        int x=0,y=0;
        java.net.URL imgURL=getClass().getResource("sorry.jpg");
                //sorry.jpg是测试图片,与Demo.class放在同一目录下35        
        ImageIcon icon=new ImageIcon(imgURL);
        g.drawImage(icon.getImage(),x,y,getSize().width,getSize().height,this);   }
    }
    }
     
      

  2.   

    例如:
    this.setIconImage((new ImageIcon("images/QQ.png")).getImage());
      

  3.   

    使用 SwingX 提供的 JXPanel 吧。
    BufferedImage image = ImageIO.read(...);
    jxpanel.setBackgroundPainter(new ImagePainter(image));
      

  4.   

    这不是背景图片,draw()画在前端