Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计 » Swing  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 淡入淡出效果?
aqipig



发贴: 0
积分: 0
于 2002-12-23 22:11 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如何实现图象淡入淡出效果,即图象的透明度从最大递减至0,再从0递增至最大,如此循环往复。


作者 Re:淡入淡出效果? [Re:aqipig]
taogang

怡然如故



发贴: 209
积分: 61
于 2002-12-24 23:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
have a look of Java2D demo being with JDK bundle

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

作者 Re:淡入淡出效果? [Re:aqipig]
aqipig



发贴: 0
积分: 0
于 2002-12-28 22:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
兄弟谢了


作者 Re:淡入淡出效果? [Re:aqipig]
taogang

怡然如故



发贴: 209
积分: 61
于 2002-12-29 16:46 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Welcome


作者 Re:淡入淡出效果? [Re:aqipig]
scottding

十三部落酋长

CJSDN高级会员


发贴: 1054
积分: 101
于 2002-12-30 08:32 user profilesend a private message to usersend email to scottdingsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
hoho,猪猪的问题终于解决了。


作者 Re:淡入淡出效果? [Re:aqipig]
darren



发贴: 0
积分: 0
于 2003-01-15 23:42 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我们学校出的那本书都有这也例子。。呵呵


作者 Re:淡入淡出效果? [Re:aqipig]
mmx



发贴: 0
积分: 0
于 2003-01-17 14:15 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
推荐一个例子程序。 jdk目录下/demo/jfc/java2D
我研究一个多星期了。感觉受益匪浅。
可以运行 jdk目录下/demo/jfc/java2D/java2Demo.html看一下效果



作者 Re:淡入淡出效果? [Re:aqipig]
justinnc



发贴: 0
积分: 0
于 2003-01-18 17:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不错



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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