Java Reference
In-Depth Information
Chapter 15 Self Test
1 . What method is called when an applet first begins running? What method is called
when an applet is removed from the system?
2 . Explain why an applet must use multithreading if it needs to run continually.
3 . Enhance Try This 15-1 so that it displays the string passed to it as a parameter. Add a
second parameter that specifies the time delay (in milliseconds) between each rota-
tion.
4 . Extra challenge: Create an applet that displays the current time, updated once per
second. To accomplish this, you will need to do a little research. Here is a hint to
help you get started: One way to obtain the current time is to use a Calendar object,
which is part of the java.util package. (Remember, Oracle provides online docu-
mentation for all of Java's standard classes.) You should now be at the point where
you can examine the Calendar class on your own and use its methods to solve this
problem.
5 . Briefly explain Java's delegation event model.
6 . Must an event listener register itself with a source?
7 . Extra challenge: Another of Java's display methods is drawLine( ) . It draws a line in
the currently selected color between two points. It is part of the Graphics class.
Using drawLine( ) , write a program that tracks mouse movement. If the button is
pressed, have the program draw a continuous line until the mouse button is released.
8 . Briefly describe the assert keyword.
9 . Give one reason why a native method might be useful to some types of programs.
10. Extra challenge: Try adding support for MouseWheelEvent to the MouseEvents ap-
plet shown in the section “Using the Delegation Event Model.” To do this, imple-
ment the MouseWheelListener interface and add the applet as listener for this event
by using addMouseWheelListener( ) . You will need to use Java's API documenta-
tion to find the details about these items. No answer is given for this question. You
must use your skills to provide your own solution.
Search WWH ::




Custom Search