Class 8 - Assignment
Deitel & Deitel: Problem 10.30 - 10.34 (one program); 13.25 - 13.26
Assigned Dec 14, 1998; due Dec 21, 1998, at midnight.
- Problem 10.30 - 10.34
Write an applet using methods from interfaces MouseListener
and MouseMotionListener that allows the user to press the
mouse button, drag the mouse and release the mouse button. As the user drags
the mouse, and when the mouse is released, draw a shape with the appropriate
upper-left corner, width and height. Use a separate event-listener class to
handle the mousePressed, mouseDragged, and
mouseReleased events. Hint: the mousePressed method should
capture the set of coordinates at which the user presses and holds the mouse
button initially and the mouseDragged and
mouseReleased methods should capture the set of coordinates
at which the user has dragged the mouse to or released the button. Both
methods should call methods in the applet to set appropriate coordinate
values. All calculations of the width, height, and upper-left corner should
be performed by the paint method before the shape is
Provide a Choice button to allow the user to select which
shape to draw. The choices should include at least Rectangle, Oval,
Line, and Rounded Rectangle.
Allow the user to select the drawing color.
Allow the user to specify if a shape should be filled or empty when it
is drawn. The user should click a Checkbox to indicate
filled or empty.
- Problem 13.25 - 13.26
Write a program that bounces a blue ball inside an applet. The ball
should be initiated with a mousePressed event. When the ball
hits the edge of the applet, the ball should bounce off the edge at a
randomly selected angle between 20 and 60 degrees.
Allow the user to draw up to five lines on the applet while the ball is
bouncing. When the ball hits a line, it should bounce off the line
at a randomly selected angle between 20 and 60 degrees.