src/com/zzk/panel/BackgroundPanel.java
(完整代码) 982Bpackage com.zzk.panel;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.JPanel;
/**
* 版权所有: 西安市华育国际学员
*
* 完成日期: 2013-05-15
*
* 项目出处: 编程词典
*
* 服务社区: www.hygj.com
*
* 制作人: 文敏
*
*/
public class BackgroundPanel extends JPanel {
private Image image; // 定义图像对象
public BackgroundPanel(Image image) {
super(); // 调用超类的构造方法
this.image = image; // 为图像对象赋值
}
/*
* 重写paintComponent方法
*/
protected void paintComponent(Graphics g) {
super.paintComponent(g); // 调用父类的方法
Graphics2D g2 = (Graphics2D) g; // 创建Graphics2D对象
if (image != null) {
int width = getWidth(); // 获得面板的宽度
int height = getHeight(); // 获得面板的高度
// 绘制图像
g2.drawImage(image, 0, 0, width, height, this);
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
