【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:BackLabel.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
package com.lzw.view;
import java.awt.*;
import java.net.URL;
import javax.swing.*;
import java.awt.Dimension;
public class BackLabel extends JLabel {
public int width, height;
private Image img;
public BackLabel() {
super();
URL url = getClass().getResource("/images/main.png");
img = new ImageIcon(url).getImage();
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
g.drawImage(img, 0, 0, width,height,this);
}
}