Java Reference
In-Depth Information
3. Enter the code from Figure 8-21 on page 509.
The TextPad window displays the code for the window listener, which
completes the BillPayer() constructor method (Figure 8-24).
showConfirmDialog()
method
addWindowListener()
method
JOptionPane
attribute
FIGURE 8-24
The System.exit argument usually is one (1) if the program terminates for an
error and zero (0) if the program proceeds to its natural conclusion (i.e., the user
clicks the Close button). If the window is closed successfully, the open data file
also will close.
Writing Data to a Sequential Data File
Table 8-10 summarizes the methods from the Data Stream class that transfer
data to and from data files. Notice that there is no writeString() method. Instead,
Java Strings are read or written using a UTF() method. UTF stands for Unicode
Transformation Format , which is an encoding scheme that assigns a number to
each symbol. The UTF() methods provide a way to read and write formatted
data without concern for the specific data type, although the underlying mecha-
nism still is reading one byte at a time.
Table 8-10
Methods to Read and Write from the Data Stream Class
TYPE OF DATA
INPUT METHOD
OUTPUT METHOD
EXAMPLE
boolean data
readBoolean()
writeBoolean()
true or false, stored as
a 1 or 0
single character data
readChar()
writeChar()
a
integer
readInt()
writeInt()
7
double
readDouble()
writeDouble()
3.12E+10
float
readFloat()
writeFloat()
5.21
9 * 10 18
long
readLong()
writeLong()
Strings
readUTF()
writeUTF()
Cashman's
 
Search WWH ::




Custom Search