The little drawing system that I showed in class
today is rather clunky, because it relies on two
different types of objects -- TextLabel
, and
Drawable
(and the various subclasses of Drawable
),
both of which use similar
methods, but must be referenced separately.
Because of this, my code currently has two different arrays and two different logic loops for each of the three main operations: drawing, containment testing, and moving.
Your assignment is to
get rid of this redundancy by having
the drawing program use an interface
named Movable
.
When you download and expand the zip file
apr-21.zip, you will
see a subfolder called movable
.
This folder is the package which contains the interface
source file Movable.java
, which
has the following contents:
package movable; import java.awt.*; public interface Movable { public void move(int dx, int dy); public void moveTo(int x, int y); public boolean contains(int x, int y); public void draw(Graphics g); }Since I've already implemented the required methods within both
Drawable
and TextLabel
.
What you need to do is the following:
Drawable.java
and TextLabel.java
that they implement Movable
.
This will require you to do two things:
import movable.*;
implements Movable
to the end.
SceneApplet.java
so that the two arrays
Drawable drawables[]
and
TextLabel textLabels[]
are replaced by a single array
Movable movables[]
.
After you do this, there should only be a single loop for drawing, a single loop for containment testing, and a single loop for moving the selected object (where now there are two separate loops for each of these operations).