troubleshooting Question

class not abstract and does not override abstract method problem

Avatar of nhay59
nhay59 asked on
8 Comments2 Solutions8333 ViewsLast Modified:

Back again. I'm now trying to extend my graphics program to allow a user to drag the PacMan drawing around the window to a new location. I have added the required code, but get the following error when I try to compile it,

PacMan_clickstest is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener

Why would it throw up this error, and what is the best way to correct this problem?

My current code is as follows,

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;

public class PacMan_clickstest extends JPanel implements MouseListener, MouseMotionListener{
    public static int mode = 0;
    private static JButton rightButton;
    private static JButton leftButton;
    int last_x, last_y;
    Rectangle rect;
    boolean pressOut = false;
    public PacMan_clickstest(){
        this.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                last_x = e.getX();
                last_y = e.getY();
                pressOut = rect.contains(e.getX(), e.getY());
            public void mouseDragged(MouseEvent e){
                if ( !pressOut)
            public void mouseReleased(MouseEvent e) {}
            public void mouseMoved(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
            //public void mouseExited(MouseEvent e){}
            public void mouseEntered(MouseEvent e){}
            public void updateLocation(MouseEvent e) {
                rect.translate(e.getX() - last_x, e.getY() - last_y);
                last_x = e.getX();
                last_y = e.getY();

public void paintComponent(Graphics g) {
    Dimension d = getSize();
    Graphics2D g2 = (Graphics2D)g;
    int size = 100;
    Ellipse2D.Double head =
            new Ellipse2D.Double(0, 0, size, size);
    Ellipse2D.Double eye =
            new Ellipse2D.Double(size/2-1, size/5-1,
            size/10, size/10);
    GeneralPath mouth = new GeneralPath();
    mouth.moveTo(size, size/4);
    mouth.lineTo(size/8, size/2);
    mouth.lineTo(size, size*3/4);
    Area pacman = new Area(head);
    pacman.subtract(new Area(eye));
    pacman.subtract(new Area(mouth));

public static void main(String[] args) {
    JFrame frame = new JFrame("Drawing stuff");
    Container contentPane = frame.getContentPane();
    JPanel panel = new JPanel();
    PacMan_clickstest pacman = new PacMan_clickstest();
    leftButton = new JButton("Leftt");
    rightButton = new JButton("Right");
    contentPane.add(panel, BorderLayout.SOUTH);
    contentPane.add(pacman, BorderLayout.CENTER);
    frame.setSize(600, 600);
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {

Any advice or help appreciated. Many thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros