Given a UML diagram of:
Oval
-------
-------
+draw (g:Graphics, x:int, y:int)
+toString(): String
I have currently
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Oval extends Shape
{
public Oval (Color color, boolean isFilled, int width)
{
super (color, isFilled, width);
}
public void draw (Graphics g, int x, int y)
{
}
public String toString()
{
String s = super.toString() + "Shape is: Oval";
return s;
}
}
The way this works, the draw method here will overwrite the draw method in Shape. Ironically, there is absolutely nothing in the Shape draw method.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Shape
{
protected Color color;
protected boolean isFilled;
protected int width;
public Shape (Color color, boolean isFilled, int width)
{
this.color = color;
this.isFilled = isFilled;
this.width = width;
}
public void draw (Graphics g, int x, int y)
{
}
public String toString()
{
String s = color.toString() + "" + isFilled + "" + width + "";
return s;
}
}
For 1, I am not even sure this is the way it is supposed to be written and 2, for the draw method how does it work with the 3 variables? I thought that the Graphics g was a paint component.
The only instruction is that the Oval should be drawn with a height equal to 1.5 times their width. Again, with the proper API on the docs.oracle.org for the drawRect, I would need the x and y cord for a starting place, which need to be centered in the middle of the shape. However in my instructions there is no indication of what that is.