next up previous
Next: Program Walkthrough: Class Definition Up: In the Laboratory: Editing, Previous: Program Walkthrough: Program Style

Program Walkthrough: The import Declaration

The next portion of the program contains the three import statements:


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


The import statement is a convenience that allows you to refer to library classes by their short names rather than by their fully qualified names. For example, the first import statement tells the compiler that in this program we will refer to the java.applet.Applet class simply as Applet. This allows us to write a statement like


public class FirstApplet extends Applet


instead of being required to use the full name for the Applet class


public class FirstApplet extends java.applet.Applet


But either will work. The expression java.awt.* uses the asterisk (``*'') as a wildcard character that matches any public class name in the java.awt package. This allows you to refer to all public classes in the java.awt package--for example, java.awt.Button and java.awt.TextArea--by their short names. The third statement matches all the class names in the java.awt.event package, which allows the program to refer to java.awt.event.Action Listener by its short name.


next up previous
Next: Program Walkthrough: Class Definition Up: In the Laboratory: Editing, Previous: Program Walkthrough: Program Style
Ralph Morelli {Faculty} 2002-03-02