Java Reference
In-Depth Information
The
TestData
program uses nested
for
loops to compute random values and
write them to the output file. After all values are printed, the file is closed. Output
files must be closed explicitly to ensure that the data is retained. In general, it is
good practice to close all file streams explicitly when they are no longer needed.
SELF-REVIEW QUESTIONS
(see answers in Appendix N)
SR 11.13
What is a stream?
SR 11.14
What are the standard I/O streams?
SR 11.15
What
Stream
class object have we been using explicitly throughout
this topic?
SR 11.16
An I/O exception, the
InputMismatchException
, will occur during
the
main
method of the
CreatingExceptions
program (see Listing
11.5) if the user enters an alphabetic character. Why doesn't the
main
method definition include a throws
InputMismatchException
clause?
SR 11.17
An I/O exception, the
FileNotFoundException
, will occur during
the
main
method of the
TestData
program if the
test.dat
is not
writable. Why doesn't the
main
method definition include a throws
FileNotFoundException
clause?
SR 11.18
What happens if the
PrintWriter
constructor of the
TestDate
class
is passed the
fw
object instead of the
bw
object?
Let's take a look at a some special features that can be used with any Swing com-
ponent. Appropriate application of these features can enhance the user interface
and facilitate the use of the components. This section describes the use of tool tips
and mnemonics, as well as the ability to disable components, then explores an
example that uses these features.
Any Swing component can be assigned a
tool tip,
which is
a short line of text that will appear when the cursor is rested
momentarily on top of the component. Tool tips are usually
used to inform the user about the component, such as the
purpose of a button.
A tool tip can be assigned using the
setToolTipText
method of a Swing com-
ponent. For example:
JButton button =
new
JButton ("Compute");
button.setToolTipText ("Calculates the area under the curve.");
KEY CONCEPT
Tool tips and mnemonics can
enhance the functionality of a
graphical user interface.
Search WWH ::
Custom Search