//
//  MyTutorial.java
//  MyTutorial
//
//  Created by Maree Kuulma on 13/08/13.
//  Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//
//  A simple signed Java applet
//

import java.awt.*;
import java.applet.*;
import javax.swing.*;

public class MyTutorial extends Applet implements Runnable {
	
	int i, num = 19;
	Thread mover = null;
	Image[] photos = new Image[num];
	AudioClip backing;
	int curone = 0;
	String prefix = "RubyDesktopApplication-";
	
	
    public void init() {
	    String fname;
		for (int ii=0; ii<num; ii++) {
		  fname = prefix + Integer.toString(ii) + "of.jpg";
		  photos[ii] = getImage(getCodeBase(), fname);
		}
		backing = getAudioClip(getCodeBase(), "shuffle.au");
    }
	
	public void start() {
		if (mover == null) {
			mover = new Thread(this);
			mover.start();
		}
	}
	
	public void stop() {
		mover = null;
	}
	
	public void run() {
		while (mover != null) {
			curone++;
			if ((curone % 4) == 0) backing.play();
			if (curone > num) curone = 0;
			repaint();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException ex) {
			}
		}
	}
	
    public void paint (Graphics g) {
        super.paint(g);
		g.drawImage(photos[curone],100,100,this);
    }
}
