import acm.program.*;
import acm.graphics.*;
import java.awt.event.*;
public class MouseTracker extends GraphicsProgram {
public void run() {
label = new GLabel("");
label.setFont("Times New Roman-36");
add(label, 50, 50);
addMouseListeners();
}
public void mouseMoved(MouseEvent e) {
label.setLabel("Mouse: (" + e.getX() + ", " + e.getY() + ")");
}
private GLabel label;
}
When we import acm.graphics., we start being able to call Glabel constructor and invoke methods on it, true? Then why do we need to do "extends GraphicsProgram" when we have imported acm.program. package which has acm.program.GraphicsProgram class meaning me can call the method add(label, 50, 50).
Ok import is just a short way to access the class, but I could create Glabel object and call its method setFont in my class. Is this 0 funcionality? Finally why could not I do the same with add method, just access the class and call it without inherinting the class.


Sign In
Create Account

Back to top









