Cannot find addMouseListeners () character method in acm.program.GraphicsProgram

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:

/*
 * 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;

}

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?

+4
source share
1 answer

, karel.jar, , CS106A, addMouseListeners(). karel.jar .

+1

Source: https://habr.com/ru/post/1532505/


All Articles