5.5 Exercises



1. Dragging a square

Write the code for the following applet. It displays a square that can be dragged.

2. Adding a check box

The scratchpad applet of the section on canvases is extended below with facilities to choose the color. The original code consists of two parts: for the applet and for the canvas. Make the necessary additions to the code to obtain a similar extension.

3. AWT Version of encryption and decryption

In an exercise of chapter 4, the goal was to encrypt and decrypt message. Make an AWT version which consists of an applet with textfields for the encrypted and decrypted message. It should look like:

4. Wall paper applet

Using geometric shapes, we can make a wall paper. The goal is to write an applet that uses the Shape classes to draw on the screen. The shapes are positioned at random, but may be dragged to an other position. Also shapes may be deleted.