Swing/Wipe のバックアップの現在との差分(No.16)
- category: swing folder: Wipe title: Wipeアニメーションで画像を表示 tags: [Animation, Image, Timer] author: aterai pubdate: 2004-10-18T02:23:59+09:00 description: WipeアニメーションでPNG画像を表示します。 image:
概要
Wipe
アニメーションでPNG
画像を表示します。
Screenshot
Advertisement
サンプルコード
class WipeImage extends JComponent implements ActionListener {
private int ww = 0;
public WipeImage() {
super();
setBackground(Color.BLACK);
}
#spanadd
#spanend
@Override protected void paintComponent(Graphics g) {
super.paintComponent(g);
int iw = (int) icon.getIconWidth();
int ih = (int) icon.getIconHeight();
if (direction) {
if (ww < iw) {
ww += 10;
} else {
animator.stop();
}
} else {
if (ww > 0) {
ww -= 10;
} else {
animator.stop();
}
}
g.drawImage(icon.getImage(), 0, 0, iw, ih, this);
g.fillRect(ww, 0, iw - ww, ih);
}
#spanadd
#spanend
@Override public void actionPerformed(ActionEvent e) {
repaint();
}
}
View in GitHub: Java, Kotlin解説
画像の上に、徐々に位置と幅を変更しながら矩形を描画することでWipe
しています。
上記のサンプルでは、Timer
を使用して位置と幅を変更しながら画像の上に矩形を描画することでWipe
アニメーションを実行しています。