src/com/zzk/panel/BackgroundPanel.java
(完整代码) 844Bpackage com.zzk.panel;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.JPanel;
public class BackgroundPanel extends JPanel {
private Image image; // 定义图像对象
public BackgroundPanel(Image image) {
super(); // 调用超类的构造方法
this.image = image; // 为图像对象赋值
}
/*
* 重写paintComponent方法
*/
@Override
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 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
