Introduction to Java. A tutorial from A-SQUARE, Inc. January 2003

© 2000-2003 A-Square, Inc. Cambridge, MA

Source Code for WelcomeApplet.java

As always you get the sourcecode by selecting and copying any text between the two > that separate the source text from the rest of this HTML document.

>

/*
 *
 * WelcomeApplet   Version 2.0 000914
 * This is a version of an applet of the same name provided
 * in the excellent book Core Java 1.1 Volume I, Fundamentals  
 * by Cay S. Horstman and Gary Cornell
 * The SunSoft Press Java Series
 * Prentice Hall 1997
 *
 * NOTE: This applet requires a Java 1.1 enabled browser.
 */ 

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;


public class WelcomeApplet extends Applet implements ActionListener{ 
    public void start(){ 
        setLayout(new BorderLayout());
        Label l = new Label(getParameter("greeting"), Label.CENTER);
        l.setFont(new Font("Times", Font.BOLD, 18));
        add(l, "Center");
        Panel p = new Panel();
        Button b1 = new Button("RART");
        b1.addActionListener(this);
        p.add(b1);
        Button b2 = new Button("Jan Aminoff");
        b2.addActionListener(this);
        p.add(b2);
        add(p, "South"); 
    }


    public void actionPerformed(ActionEvent evt){ 
        String arg = evt.getActionCommand();
        String uName;
        URL u;
        if (arg.equals("RART")) 
            uName = "http://www.rart.com";
        else if (arg.equals("Jan Aminoff")) 
            uName = "mailto:JanAminoff@aol.com";
        else return;
        try { 
            u = new URL(uName);
            getAppletContext().showDocument(u);
        }
        catch(Exception e){ 
            showStatus("Error " + e);
        }
    }
}

>