import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Fram extends Applet {
  String titlestr;
  int iwidth, iheight, index, num_im;
  /* Global variables */
  Image im[], foo;
  AudioClip au[];

  public void init() {
    /* Get screen width and height (cool that we can do this!) */
    Toolkit t = getToolkit();
    Dimension d = t.getScreenSize();
    iwidth = d.width;
    iheight = d.height;
    /*    */
    setBackground(Color.lightGray);
    titlestr = getParameter("slideshowtitle");
    Button b = new Button("Click to Start");
    Label TLabel = new Label(titlestr,Label.CENTER);
    setLayout(new BorderLayout(10,10));
    add("South",b);
    add("Center",TLabel);
  }

  public boolean action(Event e, Object o) {
    if (e.target instanceof Button) {
      /* call TheSlideShow */
      foo = getImage(getDocumentBase(),"test2.gif");
      CloseableFrame f = new CloseableFrame(titlestr);
      //Graphics g = f.getGraphics();
      Applet a = new TheSlideShow(iwidth,iheight,titlestr,foo,f);
      f.setSize(iwidth,iheight);
      f.setResizable(false);
      f.setCursor(Frame.CROSSHAIR_CURSOR);
      f.show();
      f.add(a);
      // Don't need the following:
      /* f.addWindowListener(new WindowAdapter() {
	public void windowClosing(WindowEvent e) {
	  System.exit(0);
	}
      });*/      
    }
    return true;
  }
}

class TheSlideShow extends Applet {
  protected Panel p1, p2;
  protected int width, height;
  protected String ftitle;
  protected Button previousb, audiob, nextb;
  protected Image foo;
  protected int iwidth, iheight;
  protected CloseableFrame f;
  
  public TheSlideShow(int iwidth, int iheight, 
                            String ftitle, Image foo, CloseableFrame f) {

    p1 = new Panel();
    p1.setLayout(new FlowLayout(FlowLayout.CENTER));
    p2 = new Panel();
    previousb = new Button("Previous");
    audiob = new Button("Audio");
    nextb = new Button("Next");
    p2.add(previousb);
    p2.add(audiob);
    p2.add(nextb);
    setLayout(new BorderLayout());
    add("Center",p1);
    add("South",p2);

    System.out.println(iwidth+"   "+iheight);
    repaint();
    System.out.println(
         "Width and height = "+getSize().width+"  "+getSize().height);
    while( foo.getWidth(this) < 0 );
    int imwidth = foo.getWidth(this);
    System.out.println("ImWidth foo this = "+imwidth);
    int goober = this.getSize().width;
    System.out.println("this.getSize  "+goober);
  }

  public void paint(Graphics g) {
    g.setColor(Color.darkGray);
    g.fillRect(0,0,iwidth,iheight);
    g.drawImage(foo,0,0,iwidth,iheight,this);
    //g.drawImage(im[index],ix0,iy0,iw,ih,this);
    // for "DEMO" version. Comment out these lines for shippable version.
    Font myfont = new Font("TimesRoman",Font.BOLD,24);    // DEMO
    g.setFont(myfont);                                    // DEMO
    g.setColor(Color.red);                                // DEMO
    g.drawString("Demonstration version . . .",100,100);  // DEMO
  }

}

