Wipeアニメーションで画像を表示

編集者:Terai Atsuhiro
作成日:2004-10-18
更新日:2021-11-18 (木) 11:29:22

概要

WipeアニメーションでPNG画像を表示します。

http://terai.xrea.jp/swing/wipe/screenshot.png

サンプルコード

class WipeImage extends JComponent implements ActionListener {
  private int ww = 0;
  public WipeImage() {
    super();
    setBackground(Color.black);
  }
  public void paintComponent(Graphics g) {
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    if(mode) {
      if(ww<((int) (icon.getIconWidth()))) ww=ww+10;
      else animator.stop();
    }else{
      if(ww>0) ww=ww-10;
      else animator.stop();
    }
    g.drawImage(icon.getImage(), 0, 0, 
                (int) (icon.getIconWidth()),
                (int) (icon.getIconHeight()), this);
    g.fillRect(ww, 0,
               (int) (icon.getIconWidth()),
               (int) (icon.getIconHeight()));
  }
 }

解説

javax.swing.Timerを使って表示する画像の幅をすこしずつ変更しています。

コメント