1 36 37 40 41 package java2d.demos.Images; 42 43 import java.awt.*; 44 import javax.swing.JButton ; 45 import java.awt.image.ImageObserver ; 46 import java2d.AnimatingSurface; 47 import java2d.DemoPanel; 48 49 50 53 public class DukeAnim extends AnimatingSurface implements ImageObserver { 54 55 private static Image agif, clouds; 56 private static int aw, ah, cw; 57 private int x; 58 private JButton b; 59 60 61 public DukeAnim() { 62 setBackground(Color.white); 63 clouds = getImage("clouds.jpg"); 64 agif = getImage("duke.running.gif"); 65 aw = agif.getWidth(this) / 2; 66 ah = agif.getHeight(this) / 2; 67 cw = clouds.getWidth(this); 68 dontThread = true; 69 } 70 71 72 public void reset(int w, int h) { 73 b = ((DemoPanel) getParent()).tools.startStopB; 74 } 75 76 77 public void step(int w, int h) { } 78 79 80 public void render(int w, int h, Graphics2D g2) { 81 if ((x -= 3) <= -cw) { 82 x = w; 83 } 84 g2.drawImage(clouds, x, 10, cw, h-20, this); 85 g2.drawImage(agif, w/2-aw, h/2-ah, this); 86 } 87 88 89 public boolean imageUpdate(Image img, int infoflags, 90 int x, int y, int width, int height) 91 { 92 if (b.isSelected() && (infoflags & ALLBITS) != 0) 93 repaint(); 94 if (b.isSelected() && (infoflags & FRAMEBITS) != 0) 95 repaint(); 96 return isShowing(); 97 } 98 99 100 101 public static void main(String s[]) { 102 createDemoFrame(new DukeAnim()); 103 } 104 } 105 | Popular Tags |