import java.awt.*; // use graphics // This Sprite is a RightLeftBuggle with an eye. // It can "see" more, so it's a spy! // Example of creating new objects using inheritance. public class SpyBuggle extends RightLeftBuggle { // No additional instance variables necessary // Constructors // Java requires us to write constructors here because // we wrote non-default constructors in our superclass. // So, we just ask to call the constructor method of our // superclass (RightLeftBuggle) by using the keyword super. // Default constructor is required if we want to use it and // if we will be extending the class and will write constructors // that do not explicitly reference a superclass constructor. public SpyBuggle () { //super(); // this isn't necessary since super() is always called by default } public SpyBuggle (Color c, int size, int startX, int y, int dx) { // invocations of superclass constructors must be first statement in method super(c, size, startX, y, dx); } // Required Sprite methods. Only overwrite the ones which are different. public void drawState (Graphics g) { super.drawState(g); // draw the buggle just like our superclass // add an eye (color is already black) if (headedRight) { g.fillOval(currentX+size/4,y+size/3,size/8,size/8); } else { g.fillOval(currentX-(3*size)/8,y+size/3,size/8,size/8); } } // For Debugging public String className () { return "SpyBuggle"; } }