- import java.awt.*;
- import java.applet.*;
- import java.net.*;
- public class easyCam extends Applet {
- private Image myImage = null;
- private int startIndex = 1;
- private int endIndex = 9;
- private int currentIndex;
- private int sleepTime = 500;
- private String fileBase;
- private String fileExtension;
- private Thread timerThread;
- private volatile boolean noStopRequested;
- private MediaTracker tracker;
- public void init() {
- tracker = new MediaTracker(this);
- String strStartIndex = getParameter("STARTINDEX");
- String strEndIndex = getParameter("ENDINDEX");
- String strSleepTime = getParameter("MSDELAY");
- fileBase = getParameter("FILEBASE");
- fileExtension = getParameter("FILEEXT");
- if (strStartIndex != null)
- startIndex = Integer.parseInt(strStartIndex);
- if (strEndIndex != null)
- endIndex = Integer.parseInt(strEndIndex);
- if (strSleepTime != null)
- sleepTime = Integer.parseInt(strSleepTime);
- startThread();
- }
- private void startThread() {
- noStopRequested = true;
- Runnable r = new Runnable() {
- public void run() {
- runWork();
- }
- };
- timerThread = new Thread(r, "Timer");
- timerThread.start();
- }
- private void stopThread() {
- noStopRequested = false;
- timerThread.interrupt();
- }
- private void runWork() {
- currentIndex = startIndex;
- boolean imageload = false;
- try {
- while ( noStopRequested ) {
- currentIndex = currentIndex + 1;
- if( currentIndex > endIndex )
- currentIndex = startIndex;
- if( imageload == true ) {
- tracker.removeImage(myImage);
- myImage.flush();
- myImage = null;
- }
- myImage = getImage(getDocumentBase(), fileBase + Integer.toString(currentIndex) + fileExtension);
- tracker.addImage(myImage, 0);
- tracker.waitForAll();
- imageload = true;
- repaint();
- Thread.sleep( sleepTime );
- }
- } catch ( InterruptedException x ) {
- Thread.currentThread().interrupt();
- }
- }
- public void paint(Graphics g) {
- update(g);
- }
- public void update(Graphics g) {
- if( myImage != null ) {
- g.drawImage(myImage, 0, 0, this);
- }
- }
- public void destroy() {
- stopThread();
- myImage.flush();
- myImage = null;
- }
- }