Tag: Delay cell current WIM get color public This run
This is the simplest application to animate an array of images.
Import java.awt.*; Import javax.swing.*; public classAnimappExtends JComponent implements Runnable {image[] images = new IMAGE[2]; int frame = 0; public void Paint (Graphics g) {image image = Images[frame]; if (image = null) {//Draw the current image int x =0; int y =0; G.drawimage (image, X, y, this); }} public void Run () {//Load the array of images images[0] = new ImageIcon ("Image1.gif"). GetImage (); IMAGES[1] = new ImageIcon ("Image2.gif"). GetImage (); Display each image for 1 second int delay = +; 1 second try {while (true) {//Move to the next image frame = (frame+1)%images.length; Causes the Paint () method to be called repaint (); Wait Thread.Sleep (delay); }} catch (Exception e) {}} public static void Main (string[] args) { Animapp app = new Animapp (); Display the animation in a frame JFrame frame = new JFrame (); Frame.getcontentpane (). Add (app); Frame.setsize ( -, -); Frame.setvisible (TRUE); (New Thread (APP)). Start (); } }
e581. Animating an Array of Images in an application