Home -> Workshops -> STA 2000 Java Workshop -> Slide Applet
Copy all into Editor and save as Slide.java
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class Slide extends Applet implements ActionListener
{ private Button next = new Button("Next");
private Button prev = new Button("Previous");
private int imageID = 0;
private Image images[] = null;
public void init()
{ Panel buttons = new Panel();
buttons.setLayout(new FlowLayout());
buttons.add(next);
buttons.add(prev);
images = new Image[2];
images[0] = getImage(getDocumentBase(),
"picture1.jpg");
images[1] = getImage(getDocumentBase(),
"picture2.jpg");
setLayout(new BorderLayout());
add("South", buttons);
next.addActionListener(this);
prev.addActionListener(this);
}
public void paint(Graphics g)
{ g.drawImage(images[imageID], 0, 0, this);
}
public void actionPerformed(ActionEvent ae)
{ if ((ae.getSource() == next) && (imageID <
images.length-1))
imageID++;
else if ((ae.getSource() == prev) && (imageID
> 0))
imageID--;
}
}