
|
|
Magercises: AWT
Programming
Introduction
These Magercises show how to use Java's Abstract Window Toolkit components to interact
with Java forms and windows. The focus of this set of Magercises is on events and
programming AWT applications without the use of the Visual Composition Editor (VCE).
There are seven Magercises to complete:
- A Four-Function Calculator (part two)
Extend the previous Calculator exercise to provide communication between components and
create a fully-functional calculator application. Educational goal(s):
- learn how to connect components in the VCE.
- learn how to use non-visual classes in the VCE.
- Display a file from FileDialog
Create an application that creates and shows a FileDialog. Use getFile to obtain the
selected file name and display it as a label on the screne. Educational goal(s):
- Learn how to work with a FileDialog.
- Menus
Given an application (or applet) that constructs a Frame already containing a
"File" menu, create a "Help" menu that uses all the MenuItem
objects. Educational goal(s):
- Learn how to work with a menus.
- Rubberbanding
Draw rectangles setting the upper-left corner by pushing the mouse down and setting the
width and height by dragging. Educational goal(s):
- Learn how to draw through event handling.
- Double-Buffering
To perform smooth screen updates for drawing and animation, a technique called double-buffering
is often used. Double-buffering provides a means of performing redraws in a background
buffer (thus hiding it from the viewer), which is then in one smooth motion, copied to the
visible drawing buffer. This technique is used extensively in the animations for the Thread Magercises. In this Magercise, we are
going to use double-buffering for another, important reason--the background buffer will
record the set of elements we have drawn (recall that Java erases the applet drawing
region each time it repaints unless you modify the definition of method update).
We will combine the previous Rubberbanding
Magercise so that rectangles are drawn on the visible screen during rubberbanding, but
copied to the background "save" buffer.
How do we rubberband on top of an already-present image without erasing part of it as
we drag across? Exclusive OR mode. XOR mode allows you to draw once (perturbing the
background very slightly) and draw again, erasing without affecting the background.
Educational goal(s):
- Learn how to do smooth animation.
- Learn how to reduce flicker during animation.
- Color list
Create pop up menu displaying colors that you can select. Selecting a color changes the
color of a canvas. Educational goal(s):
- Learn how to use a Choice.
- Learn how to respond to events.
- Radio buttons
Create two radio buttons that allow a user to choose between two Java courses. Educational
goal(s):
- Learn how to use the Checkbox widget.
- Learn about grouping them into a CheckboxGroup.
|