www.pudn.com > 算法源码集合.rar > DrawingObj.java
import java.awt.*; /** * Interface for the drawing object to be drawn in the drawing panel. ** 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
Boxis a class which implements *DrawingObj, i.e. the class declaration ofBox* starts with the following line:* Then any instance of class* class Box implements DrawingObj { * ... *Boxcan 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(); *Boxcalled *box. The next line uses the methodaddDrawingObj* to addboxinto the canvasdrawingPanel, which * is an instance of the object classDrawingPanel. ** The
movemethod of the drawing object (which must be * specified) is then called to move the corresponding object to position *(x, y). Finally, theredraw()method of *DrawingPanelclass is called to refresh the panel and * delay for the object to be visible. * @see DrawingPanel * @see DrawingPanel#addDrawingObj * @see DrawingPanel#redraw */ public interface DrawingObj { /** * Paint method of the drawing object. * @param g A reference to the graphical context. */ public void draw(Graphics g); /** * This method repositions the drawing object to the new location * specified by the paramters. * @param x The x coordinate of the drawing object's new position. * @param y The y coordinate of the drawing object's new position. */ public void move(int x, int y); /** * Returns the x coordinate of the drawing object's reference point. * @return The x coordinate of the drawing object's reference point. */ public int getX(); /** * Returns the y coordinate of the drawing object's reference point. * @return The y coordinate of the drawing object's reference point. */ public int getY(); public Dimension getLimit( int dirn ); /** * Returns the limit of this object in the specified direction dirn = +1 = +x dirn = +2 = +y -1 = -x -2 = -y */ } // interface