Compile and Run a Java Applet

Set Up Tutorial Contents Prepare for Debugging

This part of the tutorial shows you how to compile a Java program, use the Java Machine Code Translator and run the program in the applet viewer.

  1. Make sure you have /usr/java/bin in your path.

    If not, add it by editing the PATH variable that is set in your .cshrc, .login or similar file, then running the source command on the changed file.

  2. In the QuickMenu directory, compile the QuickMenu.java file as follows:
    javac QuickMenu.java
    

    This generates five .class files:

    ParamString.class
    QMenuLink.class
    QuickMenu$MouseListener0.class
    QuickMenu$MouseMotionListener0.class
    QuickMenu.class

  3. Run the applet in the applet viewer as follows:
    appletviewer index.htm&
    

    The appletviewer command takes an argument: the HTML file that contains the applet you want to run.

    An appletviewer window opens to display the applet.

  4. In the applet viewer, check that the menu appears on sliding the mouse over the icon.

    Since the menu items are all links to URLs, there is no visible behavior when you click the menu items.

  5. Make sure that Java is enabled in your web browser by choosing Options > Network Preferences > Languages in Netscape 3.0, or Options > Security Preferences in Netscape 2.02.

  6. Run a working version of the applet in your web browser by typing into the Location field of your browser:
    file:/yourdir/QuickMenu/index.htm
    
    
                
    Set Up Tutorial Contents Prepare for Debugging

    Guide to the Cosmo Code Development Environment
    12-96*150