// $Id: DemonApplet.java,v 3.2 1998/12/09 17:11:10 jpg3u Exp $
/////////////////////////////////////////////////////////////////////
//
// File: DemonApplet.java
//
// Purpose: The DemonApplet 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
// jpg James P. Gunderson gunders@Virginia.edu
//
// Modifications:
// 09-DEC-1998 jpg Added destroy method
// 08-DEC-1998 jpg Added constructor for server, port
// 16-NOV-1998 jpg Copied from existing ClientApplet.java
//
/////////////////////////////////////////////////////////////////////
import java.applet.*;
import java.awt.*;
public class DemonApplet extends Applet {
private DemonGUI gui; // our interface to rest of Demon app
///////////////////////////////////////////////////////////////////
//
// Method: init
//
// Invoker: browser
//
// Purpose: This is called whenever the browser starts up the
// applet. Its main job is to start up the DemonGUI,
// which in turn starts up the next Module in the chain
// (i.e., DemonEngine).
//
///////////////////////////////////////////////////////////////////
public void init () {
String port = getParameter("registryPort") ;
String host = getParameter("serverName");
try {
gui = new DemonGUI (this, host, port);
}
catch (Exception e) {
Exit (e);
}
}
///////////////////////////////////////////////////////////////////
//
// 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: mouseDown
//
// Invoker: browser
//
// Purpose: This is invoked by the browser whenever the user
// clicks the mouse inside the applet. The applet does
// not handle the click but instead passes the mouse
// coordinates to DemonGUI, which handles the event.
//
///////////////////////////////////////////////////////////////////
public boolean mouseDown (Event event, int x, int y) {
gui.HandleClick (event, x, y);
return true;
}
//////////////////////////////////////////////////////////////////
//
// Method: action
//
// Invoker: browser
//
// Purpose: This is invoked by the browser whenever the user
// activates a component. This method does not
// handle the action but instead passes the action
// notification to DemonGUI, which handles the event.
//
///////////////////////////////////////////////////////////////////
public boolean action (Event event, Object object) {
try {
gui.HandleAction (event, object);
}
catch (Exception e) {
gui.Error(e);
return false ;
}
return true;
}
///////////////////////////////////////////////////////////////////
//
// Method: paint
//
// Invoker: repaint(), which is called by DemonGUI
//
// Purpose: Called by the applet's repaint() method, this enables
// the DemonGUI to display primitives in the Browser
// window by providing the DemonGUI access to the
// Graphics object.
//
///////////////////////////////////////////////////////////////////
public void paint (Graphics graphics) {
try {
gui.Draw (graphics);
}
catch (Exception e) {
Exit (e);
}
}
///////////////////////////////////////////////////////////////////
//
// Method: Exit
//
// Invoker: DemonGUI
//
// Purpose: Print specified string to console and (try to) exit.
//
///////////////////////////////////////////////////////////////////
public void Exit (Exception e) {
System.out.println ("\n");
e.printStackTrace ();
stop ();
}
} // end of class
////////////////////////////////////////////////////////////////////////