Any graphical objects to be displayed on the DrawingPanel
should implement this interface.
All the abstract methods of the interface must be defined in the
object class defining the graphical object.
For example, if Box
is a class which implements
DrawingObj
, i.e. the class declaration of Box
starts with the following line:
Then any instance of class
class Box implements DrawingObj {
...
Box
can be added to the drawing
canvas as follows:
The first line declares an instance of class
Box box = new Box(...);
drawingPanel.addDrawingObj(box);
box.move(x, y);
drawingPanel.redraw();
Box
called
box
. The next line uses the method addDrawingObj
to add box
into the canvas drawingPanel
, which
is an instance of the object class DrawingPanel
.
The move
method of the drawing object (which must be
specified) is then called to move the corresponding object to position
(x, y)
. Finally, the redraw()
method of
DrawingPanel
class is called to refresh the panel and
delay for the object to be visible.
public abstract void draw(Graphics g)
public abstract void move(int x, int y)
public abstract int getX()
public abstract int getY()