Exercises
Exercise 16-1. Modify
FirstApplet
to take advantage of the features of theGraphics
class, so that it displays the “Hello World” message in a more visually interesting way.Exercise 16-2. Modify the
Clock
applet so that it is configurable via applet parameters, like theCountdown
applet is. Your modified applet should read parameters that specify the update frequency for the time display, as well as the font, color, and format of the time display. (Seejava.text.SimpleDateFormat
for a way to format dates and times according to a specified pattern.) Also, add agetParameterInfo( )
method that describes the applet parameters you define, and modifygetAppletInfo( )
to include a message describing your contribution to the applet.Exercise 16-3. Modify the
Countdown
applet so that it responds to mouse clicks: if the mouse is clicked over the timer, it should reset the time to its initial value.Exercise 16-4. One of the key features of applets is that they are treated as untrusted code and run under a
SecurityManager
that prevents them from taking malicious actions such as reading sensitive data, deleting files, or using the client machine to send spam out across the network. Take a look again at Example 7-3 in Chapter 7, and write an applet version of that class that attempts to perform restricted actions. Use aTextField
orJTextField
component to display the applet’s output.
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.