java.applet and java.awt


Applets are applications intended to be embedded in HTML or otherwise transported across a network

The java.awt package provides an easy-to-use set of standard graphical user interface (GUI) elements.

The Java Application Programming Interface, Volume 2
James Gosling and FrankYellen


Early in the development of Java there was a mistaken view that applets simply provided an enhanced graphics environment for WebPages. In later sections we will focus on elements of Java programming that will help show why some now consider it THE Internet programming environment. In this section, however, we will focus on how Java does provide simple, familiar, elements and actions for developing user interfaces. In the process, we will also discuss how applets interact with the WebPages in which they are embedded..

First some words about the applet generic framework .

A basic templet for developing an applet is
public class name extends Applet{
public void init(){
// code to run when applet is loaded
}

public void start(){
//code to run each time the applet is started.
}

public void stop(){
//code to run each time the applet is stopped.
}
}

Default implementations for these methods are provided in Applet, however, it is usual for classes that extend Applet to override them. (There is also a fourth, fundamental, method public void destroy(){ } that is less frequently overridden.)

Some simple applets

The purpose of these examples is to provide a catalog of possible interactions that can be used in applet development. There is a bit of putting the cart before the horse in some of this but somebody has to go first!

1.The first applet applet is presented to demonstrate the fact that applets are truly part of the WebPage in which they are embedded. In particular, they respond to browser events. The applet is completely browser-event-driven.

Note
The applet does notrespond to window resizing by stop() ing, then start() ing.
The applet does not respond to window movement.
The applet does respont to leaving and returning to the Web Page.

2.The next applet adds a button to drive the action. Of course it still depends on the browser to pass mouse clicks. Moreover, other browser events are still passed. Finally, the "EVENT MODEL" used in this applet was the only one that was available in Java 1.0. Java 1.1 also provides a more powerful Model that will be discussed in a later section. Continued support for the Event Model presented in this applet seems to be an issue to be decided.

3.Next is an example of inter-applet communication throught the browser, within a WebPage.

4.The next example uses the Java Console to show interactions. This allows us to use the Java Console as an important applet debugging tool. This example also introduces the notion of a "Thread". Again, much more will be said about this in later sections.

5.The final example shows how to communicate between Java and JavaScript. There are some issues here involving BrowserWars( will it or will it not run in Internet Explorer?). Compiling the Java code is also an issue because you need to "find" netscape.javascript.

Part 4 Table of Contents


URL: https://www.umsl.edu/~siegelj/newcourse/part4/apawt.htm
Copyright: Jerrold Siegel for The University of Missouri -St. Louis