提交 | 用户 | 时间
|
ce910c
|
1 |
package com.netsdk.common; |
H |
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Graphics; |
|
5 |
import java.awt.Image; |
|
6 |
|
|
7 |
import javax.swing.JPanel; |
|
8 |
|
|
9 |
/* |
|
10 |
* 带背景的绘图面板 |
|
11 |
*/ |
|
12 |
public class PaintPanel extends JPanel { |
|
13 |
private static final long serialVersionUID = 1L; |
|
14 |
private Image image; //背景图片 |
|
15 |
|
|
16 |
public PaintPanel() { |
|
17 |
super(); |
|
18 |
setOpaque(true); //非透明 |
|
19 |
setLayout(null); |
|
20 |
setBackground(Color.GRAY); |
|
21 |
setForeground(new Color(0, 0, 0)); |
|
22 |
} |
|
23 |
|
|
24 |
//设置图片的方法 |
|
25 |
public void setImage(Image image) { |
|
26 |
this.image = image; |
|
27 |
} |
|
28 |
|
|
29 |
protected void paintComponent(Graphics g) { //重写绘制组件外观 |
|
30 |
if(image != null) { |
|
31 |
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);//绘制图片与组件大小相同 |
|
32 |
} |
|
33 |
super.paintComponent(g); // 执行超类方法 |
|
34 |
} |
|
35 |
} |