I am working on the Java Art and Science text and SEE CS106A course. Everything went smoothly until interactive graphics programs appeared. The following code, taken directly from the text, will not compile:
import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;
public class DrawLines extends GraphicsProgram {
public void run() {
addMouseListeners();
}
public void mousePressed(MouseEvent e) {
double x = e.getX();
double y = e.getY();
line = new GLine(x, y, x, y);
add(line);
}
public void mouseDragged(MouseEvent e) {
double x = e.getX();
double y = e.getY();
line.setEndPoint(x, y);
}
private GLine line;
}
Error line 14 with error cannot find symbol: method addMouseListeners(). ACM ConsolePrograms and GraphicsPrograms work fine without calling this method. As far as I can tell this method should be valid .
Am I doing something wrong here? Are the ACM documents and tutorial out of date? How to add a mouse listener here?
source
share