程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> 如何制作透明組件。

如何制作透明組件。

編輯:關於JSP

懶得寫說明了,大家應該能看懂。這是一個透明面板的例子,可仿此法制作其它透明組件。有問題給我來信。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);
}
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved