Java Exceptions  «Prev  Next»

Lesson 11

Student Project Drawing Applet

In this student project, you will work with a slightly different version of the drawing applet you saw in the last module. Here, instead of a Choice object presenting the shape types the user can draw (Square and Circle), the user can enter the shape's type into a text field along the top of the applet.
Try this for yourself, entering the name Square and Circle, and drawing by clicking the applet. Also try typing different text into the text field.


If you type something other than Square or Circle, the program does not appear to do anything.
However, this is not what is actually happening, the program is throwing an exception.

Exercise: Adding Exception Handling

To see this for yourself, copy the source code, compile it, and run it yourself using the appletviewer.

Modify Drawing - Exercise

Once you see what's going on in the source code, copy it and then begin the exercise for the student project to add your own exception handling.
Modify Drawing - Exercise