Class Library: Applications
WebFrame extends Frame implements Runnable. The application analog to WebApplet. In addition, provides getDocumentBase() and getParameter() methods which permit applications to use the same underlying class library as do applets.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class WebFrame extends Frame implements Runnable |
|
variables | WebFrame defines all the variables
defined by WebApplet. In addition, the following two variables provide functionality built into an applet but which must be defined here so that both applications and applets can share other class code. |
|
static URL documentBase = null; | Applets typically use the location of the
HTML document containing the <applet> tag (the applet's documentBase) as the
reference directory for resolving paths that are not fully qualified. There does not
appear to be any way to get an analogous reference for a Java application, so this
parameter must be set from the command line using the syntax: documentBase=somePath By default, this value is set to C:/Program Files/EarthStones. |
|
static Index params = new Index(); | Stores the application's command line arguments name1=val1 name2=val2 ... in this index of (name, val) pairs. |
|
constructors | public WebFrame(String title) | In addition to the default constructor as implemented in WebApplet, WebFrame also defines this constructor which sets the window's title. |
methods | In addition to the methods defined by WebApplet, WebFrame defines the following methods. | |
static public void main(String args[]) | This method is automatically invoked when
the application is started. Its args[] parameter is an array of strings reflecting the
(space-delimited words of the) command line. This method may be overridden in
subclasses and should have the following form: [set any default parameters here before reading command line parameters with a call to setParameters(). Use the syntax: params.add("aName", "aValue")] setParameters(args); (new WebFrame()).init(); |
|
static public void setParameters(String args[]) | 1) Reads the application's command line
parameters and set the params index to its name=value pairs. 2) Sets the URL documentBase based upon the value of the baseDirectory parameter. |
|
The next three methods provide the application's counterparts to the methods of the same names provided by the classes Applet and AppletContext. | ||
public static String getParameter(String name) | Returns the parameter value corresponding to the parameter name. | |
public URL getDocumentBase() | Returns the documentBase variable. | |
public void showDocument(URL url, String target) | 1) If the target parameter is self
or _self, and if the URL protocol is NOT ftp: or mailto: (i.e.,
the protocol is http: or file:), calls update(url.getFile(), true, false) which loads the
file identified by the url in the application's document panel. 2)Otherwise, displays a message to the user indicating why the selected resource (e.g., via hyperlink) was not loaded. Note: This method could be overrriden to load the document in a new window, another panel, etc. |
|
These three methods are involved in closing the application | ||
public void dispose() | This method is used instead of WebApplet's destroy() method, removing the Web and Site instances and calling super.dispose(). | |
public void close() | Hides the window, calls dispose(), and then calls System.exit(0) which exits the Java runtime system (JVM). | |
public boolean handleEvent(Event event) | Calls the close() method in response to the event with id = Event.WINDOW_DESTROY. | |
public int scale(int num) | This method returns a value for integer num scaled by resolutionFactor(). It duplicates a Web method not yet available when needed by this application. |
JDocViewerApp extends WebFrame. This is the application version of the JDocViewer applet. It runs as a Java console application and can be used as a mini web browser.
package | earthstones | ||
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
||
class declaration | public class JDocViewerApp extends WebFrame | ||
variables | JDocViewerApp defines the same variables as JDocViewer with the following substitution: | ||
ViewerAppFooter footer; | Applications's footer panel. | ||
constructors | public JDocViewerApp() | The default constructor. Sets window title to "JDocViewerApp". | |
public JDocViewerApp(String title) | Constructs application instance and sets title to title. | ||
methods | public void init() | Unlike JDocViewer, this application cannot rely upon an applet tag to set its location and dimensions. So this init method first calls reshape() with appropriate parameters and then proceeds as does JDocViewer.init(). | |
In addition to the methods defined by JDocViewer, JDocViewerApp defines the following: | |||
static public void main(String args[]) | 1) Sets the following parameters: params.add("autoload", "false"); params.add("baseDirectory", "C:/Progra~1/EarthStones/"); params.add("contents", "docs/JDocViewerApp/contents.htm"); 2) Calls setParameters(args). 3) Calls (new JDocViewerApp()).init(). |