日期:2014-05-20 浏览次数:20677 次
public class BackgroundPanel extends JPanel{
private static final long serialVersionUID = -4716216260810781252L;
protected Image image;
public BackgroundPanel() {
setBounds(0, 0, 400, 400);
setBackground();
}
public void setBackground() {
setImage(Toolkit.getDefaultToolkit().getImage("src"+File.separator+"image"+File.separator+"xiao.jpg"));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.WHITE);
if (image != null) {
int height = image.getHeight(this);
int width = image.getWidth(this);
if (height != -1 && height > getHeight())
height = getHeight();