Define an abstract class called `Shape' with an abstract method 'draw'.
The 'toString' method in this class can return 'Abstract Shape'. The 'draw'
method has the following prototype:
public void draw (Graphics g);
Derive two subclasses from 'Shape' called 'TwoDShape' and 'ThreeDShape'.
The 'toString' method in these classes can return the concatenation of super's
'toString' and the string '2D Shape' or '3DShape' respectively.
Derive two subclasses from 'TwoDShape' called 'Square' and 'Circle'. Have appropriate
constructors which specify the respective shapes. The 'draw' method in each of these
subclasses should implement
the code required for drawing the square and circle respectively.
Derive two subclasses from 'ThreeDShape' called 'Cone' and 'Cylinder'. Have appropriate
constructors which specify the respective shapes. The 'draw' method in each of these
subclasses should implement
the code required for drawing the cone and cylinder respectively.
To draw the cone, study the fillPolygon method in the java.awt.Graphics class.
Fill a triangle (using fillPolygon), and then fill the bottom oval.
In the Applet's 'paint' method, examine the user's choice, construct the appropriate
object, and invoke the 'draw' method with the Graphics argument. Also, the first line
in the 'paint' method should be
super.paint(g)
( Experiment without the above call.)
To repaint for each new choice, the 'actionPerformed' method should be something like
public void actionPerformed(ActionEvent e) {
if (e.getSource() == drawButton)
{
repaint();
}