<p>So I've got a <code>JPanel</code> implementing <code>MouseListener</code> and <code>MouseMotionListener</code>:</p>

<pre><code>import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class DisplayArea extends JPanel implements MouseListener, MouseMotionListener  {
    public DisplayArea(Rectangle bounds, Display display) {
        setLayout(null);
        setBounds(bounds);
        setOpaque(false);
        setPreferredSize(new Dimension(bounds.width, bounds.height));

        this.display = display;
    }

    public void paintComponent(Graphics g) {
         Graphics2D g2 = (Graphics2D)g;
         if (display.getControlPanel().Antialiasing()) {
             g2.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
         }
         g2.setColor(Color.white);
         g2.fillRect(0, 0, getWidth(), getHeight());
    }

    public void mousePressed(MouseEvent event) {
        System.out.println("mousePressed()");
        mx1 = event.getX();
        my1 = event.getY();
    }

    public void mouseReleased(MouseEvent event) {
        System.out.println("mouseReleased()");
        mx2 = event.getX();
        my2 = event.getY();

        int mode = display.getControlPanel().Mode();
        switch (mode) {
        case ControlPanel.LINE:
             System.out.println("Line from " + mx1 + ", " + my1 + " to " + mx2 + ", " + my2 + ".");
        }
    }

    public void mouseEntered(MouseEvent event) {
        System.out.println("mouseEntered()");
    }

    public void mouseExited(MouseEvent event) {
        System.out.println("mouseExited()");
    }

    public void mouseClicked(MouseEvent event) {
        System.out.println("mouseClicked()");
    }

    public void mouseMoved(MouseEvent event) {
        System.out.println("mouseMoved()");
    }

    public void mouseDragged(MouseEvent event) {
         System.out.println("mouseDragged()");
    }

    private Display display = null;

    private int mx1 = -1;
    private int my1 = -1;
    private int mx2 = -1;
    private int my2 = -1;
}
</code></pre>

<p>The trouble is, none of these mouse functions are ever called. <code>DisplayArea</code> is created like this:</p>

<pre><code>da = new DisplayArea(new Rectangle(CONTROL_WIDTH, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT), this);
</code></pre>

<p>I am not really a Java programmer (this is part of an assignment), but I can't see anything glaringly obvious. Can someone smarter than I see anything?</p>

[{'answer_id': 33715, 'author': 'Shabaz', 'author_id': 1827, 'author_profile': 'https://Stackoverflow.com/users/1827', 'pm_score': 5, 'selected': True, 'text': "<p>The <em>implements mouselistener, mousemotionlistener</em> just allows the displayArea class to listen to some, to be defined, Swing component's mouse events. You have to explicitly define what it should be listening at. So I suppose you could add something like this to the constructor:</p>\n\n<pre><code>this.addMouseListener(this);\nthis.addMouseMotionListener(this);\n</code></pre>\n"}, {'answer_id': 33716, 'author': 'Neal', 'author_id': 723, 'author_profile': 'https://Stackoverflow.com/users/723', 'pm_score': 2, 'selected': False, 'text': "<p>I don't see anywhere in the code where you call addMouseListener(this) or addMouseMotionListener(this) for the DisplayArea in order for it to subscribe to those events. </p>\n"}, {'answer_id': 33718, 'author': 'Paul Tomblin', 'author_id': 3333, 'author_profile': 'https://Stackoverflow.com/users/3333', 'pm_score': 2, 'selected': False, 'text': "<p>I don't see any code here to register to the mouse listeners.  You have to call addMouseListener(this) and addMouseMotionListener(this) on the DisplayArea.</p>\n"}]
['https://Stackoverflow.com/questions/33708', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/61/']