(阅读次数:

如何制作透明组件。

懒得写说明了,大家应该能看懂。这是一个透明面板的例子,可仿此法制作其它透明组件。有问题给我来信。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);
}
}

分享收藏到:  新浪ViVi 365Key网摘 Google书签 Windows Live Yahoo书签 添加到百度搜藏
上一篇:JSP入门教程(4)   下一篇:Java中利用散列表实现股票行情的查询(转)
[本文源自互联网,版权归原作者,转摘为学习参考使用]

评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
匿名评论
 
数据挖掘论坛导航
资讯点击排行帮
相关资讯
数据挖掘论坛资讯

关于我们  - 网站地图 - 联系方式 - 版权申明 - 友情链接 - 使用帮助
数据挖掘研究院(www.ChinaKDD.com)
增值电信业务经营许可证编号:皖B2-20040042 文网文:[2005]027号