Parts 4-7 are due on Tuesday, March 31 before class.
Write an applet which moves a rectangle across the screen along a horizontal straight line.
Use a solid red rectangle with width 100 and height 50 with upper left corner at x=75, y=50. Move this one pixel at a time with 100 ms. delay between frames to the position which has the upper left corner of the rectangle at x = 375, y=50.
Use an applet window of size 500 wide and 300 high. When the applet is started, your name appears near the bottom of the screen. Your name should always appear independent of anything else the applet does.
There should be three buttons in a horizontal row at the bottom of the window. The buttons should be labeled Init, Draw, and Move, in that order from left to right. The Init button should be enabled and the other buttons should be disabled.
When the Init button is pushed, a black line appears between the starting and ending locations of the upper left corner of the rectangle. The Draw button is enabled.
When the Draw button is pushed, the rectangle is drawn in its initial position. The Move button is enabled and the Draw button is disabled.
When the Move button is pushed the rectangle starts moving. The Move button is disabled.
At any time the Init button can be pushed which stops the motion, erases everything except your name and disables the other buttons. Pushing the Init button again shows the black line and enables the Draw button as above.
The black line segment should always be painted last so that the entire line can always be seen and should be present whenever the rectangle is. There should be no flicker on the screen as the rectangle moves.
Implement this with a thread that uses the run method of the applet.
Rewrite Part 1 so that the motion is more general. The following variables which are discussed below should be defined in your program. The run method should not make any assumptions about the values of these variables other than those assumptions which are explicitly stated.
The motion of the rectangle should be such that the x-coordinate of the upper left corner of the rectangle takes on every value between its minimum and maximum value. Similarly for the y-coordinate.
The version that appears on the web should have the parameters set to the same values as in Part 1, except that the ending location will have y=150 instead of y=50.
Rewrite Part 2 to use an external thread in which the following parameters are passed:
Rewrite Part 3 so that you can use the mouse to choose the starting and ending locations of the rectangle.
When the applet starts all buttons are disabled.
Depressing the mouse button determines the starting location of the rectangle. As the mouse is dragged, a rubber-band black line is drawn from the starting location to the current pointer position. When the mouse button is released the ending location is fixed and the black line remains in a fixed position. At this point the Init and Draw buttons are enabled. The applet behaves similarly to Part 3 with the following changes.
Pushing the Init any time it is enabled erases everything on the screen except your name and enables the mouse to specify the line of motion. Once a line of motion has been drawn, the mouse has no effect except for pushing buttons until the Init button is pushed again.
Add a slider above the buttons which controls the delay in milliseconds between frames. Changing the value of the slider only affects rectangles which are started at a later time. The range on the slider should be between 0 and 1000 milliseconds.
Rewrite Part 5 so that there are no buttons at the bottom of the applet, just the slider. The mouse is used for all control. When the mouse button is released the rectangle is drawn in its original position and immediately starts moving.
Any time the mouse button is pushed, everything on the screen is erased and the rubber-band line follows the mouse until it is released.
Rewrite Part 6 to allow multiple rectangles to be moving at once. Change the size of the rectangle to have a width of 50 and a height of 25. Every time the mouse is pushed and dragged, a new rectangle is drawn. Do an object oriented design. Think carefully about the responsibilities of the objects. Make each object as general as possible. Your program should not assume an upper bound on the number of rectangles.
On a separate page write a short description of each object you designed.