The applet code for the Marsian Slide Show
//<applet code=Slider.class width=350 height=250></applet>
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.applet.*;
public class Slider extends Applet implements Runnable {
Image[] slides=new Image[10];
Image offScreenImage;
Graphics offScreenGraphics;
Font f;
int index;
int z=0;
String slide_files[]=new String[]
{"msss_icon.jpg","Mars1.jpg",
"Mars2.gif","Mars3.jpg",
"Mars4.gif","Mars5.gif",
"Mars6.gif","Mars7.gif",
"Mars8.gif","Mars9.jpg"
};
public void init () {
this.setBackground(Color.darkGray);
index=0;
for(int i=0; i<slide_files.length;i++)
slides[i]=getImage(getDocumentBase(
), slide_files[i]);
offScreenImage=createImage(getSize().width,getSize().height);
offScreenGraphics=offScreenImage.getGraphics();
}
/* Because the images were different sizes their overlaps would
become visible.
A work around was too include resizing the pictures
relative to the container */
public void paint (Graphics g) {
g.setColor(Color.pink);
g.setFont(new Font("Monosapced",
Font.PLAIN, 22));
g.drawString("Mars Slide
Show",10,20);
g.setColor(Color.white);
g.setFont( new Font("Helvitica",
Font.ITALIC, 11));
g.drawString(" photos by
NASA (also do weddings) ",20,30);
g.drawImage (slides[index],80,60,getSize().width/2,getSize().height/2,this);
}
/* overriding update and leaving out it's clear to background reduces
the associated
flicker but only works for images of the same size overlapping
or full screen.
on the other hand, Overlapping panelling could be used
to your advantage artistically. */
public void update(Graphics g){
paint(offScreenGraphics);
g.drawImage(offScreenImage,0,0,this);
}
public void run() {
while (true) {
try{Thread.sleep(3000 );
int temp = index;
temp = ++ temp % slides.length;
index = temp;
//
j++;
//
if(j==slides.length)
//
j=0;
}
catch(InterruptedException ie){}
repaint();
}
}
Thread t;
public void start() {
t = new
Thread(this);
t.start();
}
public void stop( ) {
t.interrupt();
// Here the outlawed Thread stop( ) method is avoided
t = null;
}
}