//
// $Source: /nfs/elm/d3/home/cur/djb1/java/javat/RCS/Bounce.java,v $
//
// $Id: Bounce.java,v 1.1 1997/06/23 17:04:34 djb1 Exp $
//
// Object_Channel AWT test Applet/Application - Bounce Three
//
// (C) Copyright 1997 Dave Beckett <D.J.Beckett@ukc.ac.uk>
// University of Kent at Canterbury
//

import java.awt.*;
import java.applet.Applet;
import java.util.Vector;
import java.net.URL;
import java.net.MalformedURLException;

import Object_Channel;
import Alternative;

import ImageButtonCh;
import ScrollbarCh;

import BounceOne;

public class Bounce extends Applet {
  // Parameters to tell me what the images are called and how many there are
  private String URLprefix;
  private String URLsuffix;
  private int nFrames;
  
  // Parameter information
  private String  pinfo[][] = {
    {"URLprefix", "string", "Image URL prefix (e.g. directory/)"},
    {"URLsuffix", "string", "Image URL suffix (e.g. .gif)"},
    {"nFrames", "integer", "Number of frames"}
  };
  
  
  public void init() 
  {
    URLprefix=getParameter("URLprefix");
    URLsuffix=getParameter("URLsuffix");
    nFrames=Integer.parseInt(getParameter("nFrames"));
    
    // Create the new images from URLs and try to load them 
    Image[] images=load_images(URLprefix, URLsuffix, nFrames);
    
    BounceOne bouncer = new BounceOne(images);
    
    setLayout(new GridLayout(1,1));
    add(bouncer);
  }  
  
  
  private Image[] load_images(String URLprefix, String URLsuffix, int nFrames) {
    Image[] images= new Image[nFrames];
    for (int i=0; i<nFrames; i++) {
      try 
	{
	  String p = i<10 ? "0" : "";
	  URL url=new URL(getDocumentBase(), URLprefix + p + i + URLsuffix);
	  images[i]=getImage(url);
	}
      catch (MalformedURLException e) {
	System.err.println("Bad URL for image "+i);
      }
    }
    
    return images;
  }
  
  public String getAppletInfo() {
    return "Bounce by Dave Beckett <D.J.Beckett@ukc.ac.uk>";
  }
  
  public String[][] getParameterInfo() 
  {
    return pinfo;
  }
}
