Java Reference
In-Depth Information
32 . Window events are handled by appropriately implementing the interface
WindowListener .
33 . The class WindowAdapter implements the interface WindowListener
by providing empty bodies to the methods.
34 . To register a window listener object to a GUI component, you use the
method addWindowListener . The window listener object being regis-
tered is passed as a parameter to the method addWindowListener .
35 . Mouse events are handled by appropriately implementing the interface
MouseListener .
36 . The class MouseAdapter implements the interface MouseListener
by providing empty bodies to the methods.
37 . To register a mouse listener object to a GUI component, you use the
method addMouseListener . The mouse listener object being registered is
passed as a parameter to the method addMouseListener .
38 . Key events are handled by appropriately implementing the interface
KeyListener .
EXERCISES
1. Mark the following statements as true or false.
a. The block finally is always executed.
b. Division by zero is a checked exception.
c. File not found is an unchecked exception.
d. Exceptions are thrown either in a try block in a method or from a
method called directly or indirectly from a try block.
e. The order in which catch blocks are listed is not important.
f. An exception can be caught either in the method where it occurred or
in any one of the methods that led to the invocation of this method.
g. One way to handle an exception is to print an error message and exit
the program.
h. All exceptions must be reported to avoid compilation errors.
i. An event handler is a method.
j. A GUI component can generate only one type of event.
2. What is the difference between a try block and a catch block?
3. What will happen if an exception is thrown but not caught?
4. What happens if no exception is thrown in a try block?
5. What happens if an exception is thrown in a try block?
6.
1
1
Suppose that console is a Scanner object initialized to the standard input
device. Consider the following Java code:
 
 
Search WWH ::




Custom Search