I have the following class which uses mousePressed, mouseDragged, and mouseReleased. I've thrown some breakpoints in these methods with jdb, but I find that they aren't triggered when I try and click on my canvas. I've been working on this for a few hours and can't figure out why. Could someone offer a second set of eyes?
Thanks,
import java.awt.BasicStroke; import java.awt.Graphics2D; import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.event.MouseInputListener; class Canvas extends JPanel implements MouseInputListener { private BufferedImage m_img; private Point m_refPoint; private JLabel m_container; public Canvas() { m_img = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB); m_refPoint = null; m_container = new JLabel(new ImageIcon()); m_container.setIcon(new ImageIcon(m_img)); m_container.addMouseListener(this); m_container.addMouseMotionListener(this); } protected void draw(Point end, BufferedImage img) { Graphics2D g2 = img.createGraphics(); g2.setPaint( m_selector.getFg() ); g2.setStroke( new BasicStroke(2.0f) ); g2.draw(new Rectangle2D.Float((float)m_refPoint.x, (float)m_refPoint.y, (float)Math.abs(end.x-m_refPoint.x), (float)Math.abs(end.y-m_refPoint.y))); m_container.setIcon(new ImageIcon(img)); repaint(); } public void mousePressed(MouseEvent e) { m_refPoint = e.getPoint(); } public void mouseDragged(MouseEvent e) { if (m_refPoint == null) return; Point end = e.getPoint(); BufferedImage scratch = new BufferedImage(m_img.getColorModel(), m_img.copyData(null), m_img.getColorModel().isAlphaPremultiplied(), null); draw( end, scratch ); } public void mouseReleased(MouseEvent e) { if (m_refPoint == null) return; draw( e.getPoint(), m_img); } public void mouseClicked(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited (MouseEvent e) {} public void mouseMoved (MouseEvent e) {} }