Your task:
Write a program, that can draw simple geometric objects, and put some of these objects together to draw a picture like the
following one:
As you can see: the picture is composed using three different elements:
The minimum requirement for this assignment is to draw an image containing at least a circle, a rectangle, a line. Additionally the drawing must be programmed inside of a pre defined software framework i'll give to you.
I provide a class called 'GraphicsEngine' (a presumptuous name for such a class, i admit). This class does nothing else than
opening a window on the screen, size 500x500, and providing the actual drawing environment, which is a Java.awt.Graphics class.
The graphics class contains an array of GraphicsObjects, also a class provided by me.
GraphicsObjects is an abstract class, that only contains an abstract method 'paint', along with some fields. For each different geometric object
you must define your own class, inherited from GraphicsObject, implementing 'paint'. You will therefore at least define 3 classes,
Circle, Rectangle, Line.
To draw the image, simply add appropriate instances of your classes to the GraphicsObject-array in the class GraphicsEngine.
My class 'GraphicsEngine', though eventually being the class that triggers the drawing on the screen, does not know upfront about the elements to be drawn. So how can it be useful ? Here comes the trick, and here comes inheritance: all the geometrical objects you have to draw onto the screen must be inherited from this class, i.e. every object you want to display is a 'GraphicsObject'. What does 'GraphicsObject' offer ? Nothing else than the general properties and abilities all the objects to be drawn have in common: they all have a position, a color, and they can draw themselves. Read it again: they can draw themselves. Here's the trick, and the wonderful thing about object oriented programming: my class, the one that shows the graphics, can't draw, since it doesn't know what to draw. But it will know the objects to be drawn, so it will will just command the objects to draw themselves. All the work is on you, my class just gives the orders. I certainly like that.
'The objects can draw themselves' means: they possess a method, called 'paint(Graphics g)', being defined in GraphicsObject. In 'paint' you can do whatever you want, but you have to use the 'Graphics' object g, which will be provided by the class 'GraphicsEngine'.
To conclude: You are given 2 classes:
I will give an additional bonus point for the picture that i like best (yes, this bonus point is my subjective choice ! :-)