Java Article 2 Code:

// By Ned Etcode
// Copyright 1995, 1996 Netscape Communications Corp.  All rights reserved.

import netscape_beta.application.*;
import netscape_beta.util.*;

/** In this example we create several user interface elements and place
  * them on the root view. We set ourselves as the target of these
  * elements so that as the user interacts with them we receive the
  * corresponding commands.
public class PushMe extends Application implements Target {
    Button button;
    Slider slider;
    TextField textField;
    TextField statusField;
    GrayView grayView;

    /** This method gets called to initialize an application. We'll take
      * this opportunity to set up the View hierarchy.
    public void init() {

        // Change the color of the root view to be the standard
        // application lightGray.


        // Set up a TextField which will display status messages.  The
        // setBuffered(true) call will prevent it from flickering when someone
        // drags the slider.  After setting it up we add it as a subview of
        // the root view so that it will be displayed on the screen.

        statusField = new TextField(24, 24, 256, 24);
        statusField.setFont(Font.fontNamed("Courier", Font.PLAIN, 12));
        statusField.setStringValue("Hello World");

        // Create a button with the text "Push Me" on it.  We set ourselves
        // as the target of the button, so that we'll receive a
        // performCommand() message (see the Target interface) with the
        // command "buttonWasPressed" whenever the button is pressed.

        button = new Button(24, 64, 64, 24);
        button.setTitle("Push Me");

        // Make a Slider and tell it to send us the command "sliderWasMoved"
        // whenever the slider changes.

        slider = new Slider(24, 96, 64, 24);

        // Make a TextField which the user can edit.  The API to set the
        // target and command of a TextField will improve in a future release.

        textField = new TextField(24, 128, 64, 24);

        // GrayView is a custom View subclass which just draws solid gray
        // rectangle. We change the shade of gray it displays in the
        // sliderWasMoved() method below.

        grayView = new GrayView(128, 64, 128, 128);

    /** This is the sole method of the Target interface. Since java doesn't
      * have a way to do callbacks, this ugly little bit of code needs to
      * exist. The convention we recommend is to simply invoke the method
      * with the same name as the command.
    public void performCommand(String command, Object arg) {
        if (command.equals("buttonWasPressed"))
        else if (command.equals("sliderWasMoved"))
        else if (command.equals("textWasEntered"))

    /** This method is invoked when the button is pressed.
    public void buttonWasPressed(Object arg) {
        showStatus("Button Was Pressed!");

    /** This method is invoked when the slider moves. We set the shade of
      * gray displayed in the GrayView from the value of the slider.
    public void sliderWasMoved(Object arg) {
        showStatus("Slider Was Moved!  value = " + slider.value());

    /** This method is invoked when the user hits return in the TextField.
    public void textWasEntered(Object arg) {
        showStatus("Text Was Entered!  value = \"" +
                    textField.stringValue() + "\"");

    /** We call showStatus() from several places to update the text displayed
      * in the status field.
    public void showStatus(String status) {

    // This method allows PushMe to run as a stand alone application.
    public static void main(String args[]) {
        PushMe app;
        ExternalWindow mainWindow;
        Size size;

        app = new PushMe();
        mainWindow = new ExternalWindow();
        size = mainWindow.windowSizeForContentSize(320, 200);
        mainWindow.sizeTo(size.width, size.height);;;
Back to IFC article