WaitAnimation.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:2k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: WaitAnimation.java,v 1.1 2005/05/25 23:13:23 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  */
  7. package org.jdesktop.demo.login.romain;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import javax.swing.JComponent;
  14. import javax.swing.Timer;
  15. public class WaitAnimation extends JComponent implements ActionListener {
  16. private Image[] animation;
  17. private int index;
  18. private int direction;
  19. public WaitAnimation() {
  20. setOpaque(false);
  21. index = 0;
  22. direction = 1;
  23. MediaTracker tracker = new MediaTracker(this);
  24. animation = new Image[6];
  25. for (int i = 0; i < 6; i++) {
  26. animation[i] = UIHelper.readImage("auth_" + String.valueOf(i) + ".png");
  27. tracker.addImage(animation[i], i);
  28. }
  29. try {
  30. tracker.waitForAll();
  31. } catch (InterruptedException e) {
  32. }
  33. Timer animationTimer = new Timer(150, this);
  34. animationTimer.start();
  35. }
  36. public void paintComponent(Graphics g) {
  37. int x = (int) ((getWidth() - animation[index].getWidth(this)) / 2.0);
  38. int y = (int) ((getHeight() - animation[index].getHeight(this)) / 2.0);
  39. g.drawImage(animation[index], x, y, this);
  40. }
  41. public void actionPerformed(ActionEvent e) {
  42. index += direction;
  43. if (index > 5) {
  44. index = 5;
  45. direction = -1;
  46. } else if (index < 0) {
  47. index = 0;
  48. direction = 1;
  49. }
  50. }
  51. }