最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何制作透明组件。
时间:2022-07-02 17:23:42 编辑:袖梨 来源:一聚教程网
懒得写说明了,大家应该能看懂。这是一个透明面板的例子,可仿此法制作其它透明组件。有问题给我来信。8-)
希望与大家分享经验。
package com.borland.samples.welcome;
import java.awt.*;
public class MyPanel extends Panel {
private Image bi; // offscreen image
private Graphics big; // Graphics for the offscreen image
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
if (bi == null) { // you can't do this from the constructor
bi = createImage(getSize().width,getSize().height);
big = bi.getGraphics();
}
Rectangle area = g.getClipBounds(); // this is the area that needs to be (re)painted (no need to repaint everything)
big.setClip(area);
big.clearRect(area.x, area.y, area.width, area.height); // fills the area with the background color // the next statement will call the paint methods for the other panels/components you have added to this panel // and draw them to the offscreen image
super.paint(big);// now draw the offscreen image to the panel
g.drawImage(bi,area.x, area.y, area.x+area.width, area.y+area.height,area.x, area.y, area.x+area.width, area.y+area.height,this);
}
}
希望与大家分享经验。
package com.borland.samples.welcome;
import java.awt.*;
public class MyPanel extends Panel {
private Image bi; // offscreen image
private Graphics big; // Graphics for the offscreen image
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
if (bi == null) { // you can't do this from the constructor
bi = createImage(getSize().width,getSize().height);
big = bi.getGraphics();
}
Rectangle area = g.getClipBounds(); // this is the area that needs to be (re)painted (no need to repaint everything)
big.setClip(area);
big.clearRect(area.x, area.y, area.width, area.height); // fills the area with the background color // the next statement will call the paint methods for the other panels/components you have added to this panel // and draw them to the offscreen image
super.paint(big);// now draw the offscreen image to the panel
g.drawImage(bi,area.x, area.y, area.x+area.width, area.y+area.height,area.x, area.y, area.x+area.width, area.y+area.height,this);
}
}
相关文章
- 《潜行者2:切尔诺贝利之心》使用手电筒方法介绍 11-21
- 《潜行者2:切尔诺贝利之心》回声探测器使用攻略分享 11-21
- 《潜行者2:切尔诺贝利之心》人工制品奖励获得方法介绍 11-21
- 《潜行者2:切尔诺贝利之心》奇美拉嵌合体打法技巧分享 11-21
- 《潜行者2:切尔诺贝利之心》风衣怪打法技巧分享 11-21
- 《潜行者2:切尔诺贝利之心》变异狗打法技巧分享 11-21