home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 1.3 KB | 69 lines |
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.Applet;
-
- /*
- * display a series of images
- */
- public class ImageApp extends Applet implements ActionListener
- {
-
- /*
- * the number of images to load
- */
- final int NumImages = 6;
- Button button1;
-
-
- /*
- * an array to hold the images
- */
- Image imgs[] = new Image[NumImages];
-
- /*
- * which image is currently displayed
- */
- int which = 0;
-
- /*
- * init method runs when applet is loaded or reloaded
- */
- public void init() {
-
- setLayout(new BorderLayout());
-
- Panel p = new Panel ();
- add("South", p);
- button1 = new Button("Next Image");
- p.add (button1);
- button1.addActionListener(this);
- for (int i=0; i < NumImages; i+=1) {
- String name = "Globe"+(i+1)+".gif";
- imgs[i] = getImage (getDocumentBase(),name);
- }
- }
-
- /**
- * paint method is called by update
- * draw the current image
- * @param g - destination graphics object
- */
- public void paint (Graphics g) {
-
- g.drawImage (imgs[which], 10, 10, this);
- }
-
- /**
- * switch to next image when button is pressed
- * @param evt - event object
- * @param arg - target object
- */
- public void actionPerformed(ActionEvent evt)
- {
- which += 1;
- which %= NumImages; // wrap around to zero
- repaint (); // causes update as soon as possible
- }
- }
-
-