Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Java GUI 设计
» Swing
打印话题 寄给朋友 订阅主题 |
作者 | Re:淡入淡出效果? [Re:aqipig] |
taogang
怡然如故 发贴: 209 积分: 61 |
于 2002-12-24 23:39
a sample: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FadeIMGFrame extends JFrame { FadeIMG fimg = null; public FadeIMGFrame() { fimg = new FadeIMG(); getContentPane().add(fimg, BorderLayout.CENTER); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setTitle("Fade Image Demo"); pack(); setSize(new Dimension(500, 300)); setVisible(true); fimg.run(); } public static void main(String[] args) { new FadeIMGFrame(); } class FadeIMG extends JPanel implements Runnable { int alpha = 0; int step = 1; Image img = null; public FadeIMG() { img = this.getToolkit().createImage("image.jpg"); } /** * Calculate alpha's value from 1 to 100 then reverse */ public void run() { while (true) { try { Thread.sleep(10); } catch (Exception e) { } alpha += step; if (alpha > 99 || alpha < 1) { step = -step; } repaint(); } } public void paintComponent(Graphics g) { Dimension d = getSize(); Graphics2D g2d = (Graphics2D) g; /** * Clear the backgroup with white color */ g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, d.width, d.height); /** * Set Alpha Channel */ try { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha / 100)); } catch (Exception e) { System.out.println("\n" + alpha); } /** * Draw Image and release resource */ g2d.drawImage(img, 0, 0, this); g2d.dispose(); } } }
taogang edited on 2002-12-25 17:15
为什么这个Applet不能在浏览器显示啊? |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
43430 | 淡入淡出效果? | aqipig | 44 | 2002-12-23 22:11 |
37183 | Re:淡入淡出效果? | taogang | 1732 | 2002-12-24 23:39 |
36058 | Re:淡入淡出效果? | aqipig | 4 | 2002-12-28 22:21 |
36821 | Re:淡入淡出效果? | taogang | 7 | 2002-12-29 16:46 |
36810 | Re:淡入淡出效果? | scottding | 16 | 2002-12-30 08:32 |
36107 | Re:淡入淡出效果? | darren | 19 | 2003-01-15 23:42 |
36221 | Re:淡入淡出效果? | mmx | 100 | 2003-01-17 14:15 |
36648 | Re:淡入淡出效果? | justinnc | 2 | 2003-01-18 17:52 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |