/*
 * Gary Cornell and Cay S. Horstmann, Core Java (Book/CD-ROM)
 * Published By SunSoft Press/Prentice-Hall
 * Copyright (C) 1996 Sun Microsystems Inc.
 * All Rights Reserved. ISBN 0-13-565755-5
 *
 * Permission to use, copy, modify, and distribute this 
 * software and its documentation for NON-COMMERCIAL purposes
 * and without fee is hereby granted provided that this 
 * copyright notice appears in all copies. 
 * 
 * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR 
 * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS
 * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED 
 * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING 
 * THIS SOFTWARE OR ITS DERIVATIVES.
 */
 
/*
  AppletFrame.java
  v1.10
  Modified from v1.00 by Tero Hasu.
  */

import java.awt.*;
import java.applet.*;
import java.net.*;
import java.util.*;

public
class AppletFrame extends BaseAppletFrame
{

  private
  String[] arguments;

  public
  AppletFrame(Applet a, int x, int y, String args[])
  {  
    super(null,x,y); // actually don't use the superclass constructor
    arguments=args;
    setTitle(a.getClass().getName());
    resize(x, y);
    add("Center", a);
    a.setStub(this);
    a.init();
    setBackground(Color.white); // set color before showing
    show();
    a.start();
  }
 
  public
  String getParameter(String name)
  {
    if(arguments.length>0)
    {
      if(name.equals("file"))
	return arguments[0];
    }
    return null;
  }

}

class BaseAppletFrame extends Frame
implements AppletStub, AppletContext
{  

  public
  BaseAppletFrame(Applet a, int x, int y)
  { 
    if(a==null) return; // no applet to frame
    setTitle(a.getClass().getName());
    resize(x, y);
    add("Center", a);
    a.setStub(this);
    a.init();
    show();
    a.start();
  }
  
  public
  boolean handleEvent(Event evt)
  {
    if (evt.id == Event.WINDOW_DESTROY) 
      System.exit(0);
    return super.handleEvent(evt);
  }

  // AppletStub methods follow
  //

  public
  boolean isActive() { return true; }

  public
  URL getDocumentBase() { return null; }

  public
  URL getCodeBase() { return null; }
  
  public
  String getParameter(String name)
  {
    return "";
  }

  public
  AppletContext getAppletContext() { return this; }

  public
  void appletResize(int width, int height) {}
   
  // AppletContext methods follow
  //

  public
  AudioClip getAudioClip(URL url) { return null; }

  public
  Image getImage(URL url) { return null; }

  public
  Applet getApplet(String name) { return null; }

  public
  Enumeration getApplets() { return null; }

  public
  void showDocument(URL url) {}

  public
  void showDocument(URL url, String target) {}

  public
  void showStatus(String status) {}

}
