Source Code Structure
Step One: Important!
In order to work this project correctly, YOU MUST download from here: Lab 8.First, unzip it and drag it onto your desktop. Now you may simply import the entire project into Eclipse by going to:
File->Import->Existing Projects into Workspace
Browse to and select the Lab8 folder you've just downloaded for the root directory then hit finish.
Shape Package and Classes
Now that we have our project set up, we will create an additional package for our shapes-- call this package shapes.The shapes package will contain the following files:
- Shape.java:
- Represents any shape that can be drawn.
- We will declare an array of Shape objects in the Lab7 class, and initialize each element with a different subclass (Rectangle or Circle).
- Shape has a single abstract method draw().
- Drawing all the Shapes in our window means calling draw() on each Shape.
- This class needs to be declared abstract.
- Rectangle.java:
- Inherits from Shape.
- Overrides the draw() method with a rectangle definition.
- Circle.java:
- Inherits from Shape.
- Overrides the draw() method with a circle definition.