C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet>dir C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet>javac WelcomeApplet.java
This is a command prompt interface showing the directory path and files contained in that directory. The Java file "WelcomeApplet.java" is compiled using the "javac" command.
The Java code contained in the file creates an applet that displays a welcome message. The compiled Java program generates two class files: "WelcomeApplet$1.class" and "WelcomeApplet.class". These files can be used to run the applet.
/**
@version 1.21 2002-06-19
@author Cay Horstmann
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class WelcomeApplet extends JApplet
{
public void init()
{
setLayout(new BorderLayout());
JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER);
label.setFont(new Font("Serif", Font.BOLD, 18));
add(label, BorderLayout.CENTER);
JPanel panel = new JPanel();
JButton cayButton = new JButton("Cay Horstmann");
cayButton.addActionListener(makeURLActionListener(
"http://www.horstmann.com"));
panel.add(cayButton);
JButton garyButton = new JButton("Gary Cornell");
garyButton.addActionListener(makeURLActionListener(
"mailto:gary@thecornells.com"));
panel.add(garyButton);
add(panel, BorderLayout.SOUTH);
}
private ActionListener makeURLActionListener(final String u)
{
return new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
getAppletContext().showDocument(new URL(u));
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}
};
}
}