//     $Id: ClientApplet.java,v 3.2 1998/12/08 13:55:23 te3d Exp $    
 /////////////////////////////////////////////////////////////////////
 //
 // File: ClientApplet.java
 //
 // Purpose: The ClientApplet the applet which interfaces with the
 //          browser.  It is responsible for starting the GUI,
 //          providing the GUI a means of displaying primitives in
 //          the browser, and for catching user events and passing
 //          them to the GUI.
 //
 // Authors: txe  Travis Emmitt  emmitt@virginia.edu
 // 
 // Modifications:
 //   29-OCT-1998  txe  (v1) Initial creation
 //   03-NOV-1998  txe  Changed Client to ClientApplet, added comments
 //   06-NOV-1998  rgb  Added version control header info
 //
 //   12-NOV-1998  txe  (v2) Added GridBagLayout, style edits
 //   13-NOV-1998  txe  Added Exit(), exceptions
 //   15-NOV-1998  txe  Improved comments.
 //   16-NOV-1998  txe  Improved exceptions, comments, etc.
 //
 //   02-DEC-1998  txe  (v3) Improved format, added destroy()
 //   08-DEC-1998  txe  Gets parameters (port) from invoking web page
 //
 /////////////////////////////////////////////////////////////////////
 import java.applet.*;
 import java.awt.*;
 public class ClientApplet extends Applet {
   private ClientGUI gui;      // our interface to rest of client app
   //////////////////////////////////////////////////////////////////
   //
   // Method:  action
   //
   // Invoker: applet viewer
   //
   // Purpose: This is invoked by the applet viewer whenever the user
   //          activates a component. This method does not handle the
   //          action but instead passes it to ClientGUI.
   //   
   ///////////////////////////////////////////////////////////////////
   public boolean action (Event event, Object object) {
     gui.HandleAction (event, object);
     return true;
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  destroy
   //
   // Invoker: applet viewer
   //
   // Purpose: This gui the engine that the applet has been exited
   //          by the user.
   //
   ///////////////////////////////////////////////////////////////////
   public void destroy () {
     System.out.println ("User exiting applet...\n");
     gui.Quit ();
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  DumpStack
   //
   // Invoker: ClientGUI
   //
   // Purpose: This prints the specified exception's stack trace
   //          to the console.  It is used primarily for debugging
   //          programming errors.
   //
   ///////////////////////////////////////////////////////////////////
   public void DumpStack (Exception e) {
     System.out.println ("\n");
     e.printStackTrace ();
     stop ();
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  init
   //
   // Invoker: applet viewer
   //
   // Purpose: This is called whenever the applet viewer starts up the
   //          applet.  Its main job is to start up the ClientGUI,
   //          which in turn starts up the next Module in the chain
   //          (i.e., ClientEngine).
   //   
   ///////////////////////////////////////////////////////////////////
   public void init () {
     String address = getParameter ("ADDRESS");
     String port    = getParameter ("PORT");
     gui = new ClientGUI (this, address, port);
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  mouseDown
   //
   // Invoker: applet viewer
   //
   // Purpose: This is invoked by the applet viewer whenever the user
   //          presses a mouse button inside the applet. The applet
   //          does not itself handle the press but instead passes
   //          the mouse coordinates to ClientGUI.
   //   
   ///////////////////////////////////////////////////////////////////
   public boolean mouseDown (Event event, int x, int y) {
     gui.HandleClick (event, x, y);
     return true;
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  mouseUp
   //
   // Invoker: applet viewer
   //
   // Purpose: This is invoked by the applet viewer whenever the user
   //          releases a mouse button inside the applet. The applet
   //          does not itself handle the release but instead passes
   //          the mouse coordinates to ClientGUI.
   //   
   ///////////////////////////////////////////////////////////////////
   public boolean mouseUp (Event event, int x, int y) {
     gui.HandleRelease (event, x, y);
     return true;
   }
   ///////////////////////////////////////////////////////////////////
   //
   // Method:  paint
   //
   // Invoker: repaint(), which is called by ClientGUI
   //
   // Purpose: Called by the applet's repaint() method, this enables
   //          the ClientGUI to display primitives in the applet
   //          viewer by providing the ClientGUI access to the
   //          Graphics object.
   //   
   ///////////////////////////////////////////////////////////////////
   public void paint (Graphics graphics) {
     gui.Draw (graphics);
   }
 }
 ////////////////////////////////////////////////////////////////////////