Chapter 2 Introduction to Java Applications 65 2.4 (Web site development)
Chapter 2 Introduction to Java Applications 65 2.4 Displaying Text in a Dialog Box Although the first several programs presented in this chapter display output in the command window, many Java applications use windows or dialog boxes (also called dialogs) to display output. For example, World Wide Web browsers such as Netscape Navigator or Microsoft Internet Explorer display Web pages in their own windows. Email programs typically allow you to type and read messages in a window provided by the email program. Typically, dialog boxes are windows in which programs display important messages to the user of the program. Java s class JOptionPane provides prepackaged dialog boxes that enable programs to display messages to users. Figure 2.6 displays the same string as in Fig. 2.4 in a predefined dialog box known as a message dialog. One of the great strengths of Java is its rich set of predefined classes that programmers can reuse rather than reinventing the wheel. We use many of these classes throughout the book. Java s numerous predefined classes are grouped into categories of related classes called packages. The packages are referred to collectively as the Java class library, or the Java applications programming interface (Java API). The packages of the Java API are split into core packages and extension packages. The names of the packages begin with either java (core packages) or javax (extension packages). Many of the core and extension packages are included as part of the Java 2 Software Development Kit. We overview these included packages in Chapter 6. As Java continues to evolve, new packages are developed as extension packages. These extensions often can be downloaded from java.sun.com and used to enhance Java s capabilities. In this example, we use class JOptionPane, which Java defines for us in package javax.swing. Line 4, // Java extension packages is a single-line comment indicating the section of the program in which we specify import statements for classes in Java s extension packages. In every program that specifies import statements, we separate the import statements into the following groups: Java core packages (for package names starting with java), Java extension packages (for package names starting with javax) and Deitel packages (for our own packages defined later in the book). Line 5, import javax.swing.JOptionPane; // import class JOptionPane is an import statement. The compiler uses importstatements to identify and load classes used in a Java program. When you use classes from the Java API, the compiler attempts to ensure that you use them correctly. The import statements help the compiler locate the classes you intend to use. For each new class we use from the Java API, we indicate the package in which you can find that class. This package information is important. It helps you locate descriptions of each package and class in the Java API documentation. A Web- based version of this documentation can be found at java.sun.com/j2se/1.3/docs/api/index.html Also, you can download this documentation to your own computer from java.sun.com/j2se/1.3/docs.html Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services