4
我一直在努力通過The Art & Java科學文本和SEE CS106A課程。一切都一帆風順,直到交互式圖形程序被引入。下面的代碼,直接從文本拍攝,將無法編譯:在acm.program.GraphicsProgram中找不到符號方法addMouseListeners()
/*
* File: DrawLines.java
* -----------------------
* This program allows a user to draw lines to the canvas.
*/
import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;
public class DrawLines extends GraphicsProgram {
public void run() {
addMouseListeners();
}
/** Called on mouse press to record the coordinates of the click */
public void mousePressed(MouseEvent e) {
double x = e.getX();
double y = e.getY();
line = new GLine(x, y, x, y);
add(line);
}
/** Called on mouse drag to reposition the object */
public void mouseDragged(MouseEvent e) {
double x = e.getX();
double y = e.getY();
line.setEndPoint(x, y);
}
private GLine line;
}
它無法在線14與錯誤。沒有該方法調用的ACM ConsolePrograms和GraphicsPrograms正常工作。據我可以告訴這種方法should be valid。
我在這裏做錯了什麼? ACM文檔和教科書是否過期?我如何在這裏添加鼠標監聽器?