This lab introduces you to the concepts of inheritance, super/sub classes (also called base/derived classes or parent/child classes), interfaces, and abstract classes. You have already seen some of these ideas before, for example:
In this lab, we will look at these concepts further. In particular, we will look interfaces and abstract classes. These concepts are described in Chapter 9 of your text. We will also work through some of the lab in class in order to get you started.
You will also have the opportunity in this lab to work more with ArrayLists.
Starting Program: Download the Netbeans project ShapesProject.zip. Save it somewhere and unzip it. At the moment, it won't run because you need to implement several classes.
Overall Class Structure: The class structure you are to create is given in the diagram here.
Step 1 - Implement Shape and ShapeBase: The blue classes have already been implemented for you. The other classes you need to implement yourself. The circled numbers indicate the recommended order of implementation. Begin with the yellow classes, specifically, the Shape interface and the ShapeBase abstract class. Once these two classes are implemented you should be able to run the program. The picture it will give:
Step 2 - Implement Oval and PolyShape: Next implement the classes Oval and PolyShape. PolyShape makes use of the g.fillPolygon method. Create an Oval and Polygon shape in the JPanel's paintComponent method to make sure they work properly.
Note, you can add a loop to paintComponent so that you draw an object multiple times at different locations.
Step 3 - Implement ShapeArray: The power of the above class structure is that it allows you to create a complex scene (e.g. a house or tree) made up of multiple basic shapes (e.g. Box, Oval, PolyShape). See the house() method in the Pictures class. Before you can do this, however, you need to add a ShapeArray class which allows you to store multiple objects in an ArrayList.
Make sure the copy method in ShapeArray makes a deep copy of the ArrayList. Once the ArrayList is written, you can uncomment the house method in ShapeArray and also uncomment the code which calls the house method in MyJPanel. Once you do this, you get the following when you run the program:
Once you have all of the classes implemented. Add several new methods to Pictures and use these methods to draw a more complex scene in paintComponent. Have some fun with it.
To receive full credit, you need to:
Make sure that your Java code:
Demonstrate: Your program to the instructor or lab assistant by the due date.
Submit your .java files to Wise as attachments to Lab 9.