스윙은 Jpanel에 배경을 넣고 [돌려]

961 단어 JPanel
package com.tntxia.commonswing.panel;  
  
import java.awt.*;  
import javax.swing.JPanel;  
  
/** 
 *       Panel  
 * @author tntxia 
 * 
 */  
public class BackgroundPanel extends JPanel {  
      
    /** 
     *  
     */  
    private static final long serialVersionUID = -6352788025440244338L;  
      
    private Image image = null;  
  
    public BackgroundPanel(Image image) {  
        this.image = image;  
    }  
  
    //       ,    JPanel              
    protected void paintComponent(Graphics g) {  
        g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);  
    }  
}  

호출 방법:
Image image=new ImageIcon("images/bg.gif").getImage();  
JPanel panel = new BackgroundPanel(image);

좋은 웹페이지 즐겨찾기