Java Reference
In-Depth Information
To Save and Compile the Password Class
1. With your Data Disk in drive A, click the Save button on the Standard
toolbar.
The program changes are saved (Figure 9-41). Note that the asterisk next
to the file name, Password.java, is gone, indicating all changes are saved.
2. Click Compile Java on the Tools menu.
TextPad compiles the source code for the Password class. If TextPad notifies
you of compilation errors, fix the errors in the coding window and then
compile the source code again.
Password.java
saved (no asterisk)
Save button
FIGURE 9-41
Password.java
saved (no asterisk)
Testing a Reusable Class
The Password class should be tested to verify that all methods work as expected.
Because it has no main() method, the Password class cannot be executed directly.
A test program must be coded that creates objects of type Password and then
calls the appropriate public methods to test them. A test program for the
Password class, the PasswordDemo program, is provided on the Data Disk.
OTHER WAYS
1. Press CTRL + 1
Using a JPassword Field
A test program should provide users with an appropriate interface, allowing
them to test all supported aspects of the class. A real application using the Password
class would not want to display the password values as they are entered by the user.
For security purposes, these characters typically are replaced by another character,
called a mask , or echo character , such as an asterisk. Preventing the characters
typed as user input from displaying or substituting another character in their place
is called masking . Although a command-line interface could be used, a test pro-
gram using a graphical user interface (GUI) gives the feel of a typical application
using a password. It also allows for use of a JPassword field , which provides
masking of the entered password with alternate characters. The echo character is
an asterisk, by default, but can be changed to any character of your choice. The
PasswordDemo program supplied on the Data Disk provides a graphical user
interface (GUI) using two JPassword fields for testing the Password class
(Figure 9-42). Figure 9-43 displays the PasswordDemo source code.
 
Search WWH ::




Custom Search