Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:22:37+00:00 2026-06-17T18:22:37+00:00

When I compile the following code I get the error: The method addMouseListener(Player) is

  • 0

When I compile the following code I get the error:

The method addMouseListener(Player) is undefined for the type Player

Code:

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class Player extends Obj implements MouseListener {

    public Player() {
        super();
        addMouseListener(this);
    }

    public void mouseClicked(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
}

Here is the code for Obj class:

import java.awt.Rectangle;
import java.util.ArrayList;

public class Obj {

    protected int x, y, width, height, dx, dy, depth;
    protected double speed, direction;
    protected Rectangle bound;
    protected ArrayList<Obj> collideList;

    public Obj() {
        bound = new Rectangle(x, y, width, height);
        collideList = new ArrayList<>();
    }

    public boolean checkCollision(Obj obj1, Obj obj2) {
        boolean collide = false;

        // Temporarily move bound to where it will be next step, 
            //to anticipate a collision
        // (this is important to make sure objects don't "stick" 
            // to each other)
        obj1.getBound().translate(obj1.getDx(), obj1.getDy());
        // If their bounds intersect, they have collided
        if (obj1!=obj2 && obj1.getBound().intersects(obj2.getBound())) {
            collide = true;
        } else {
            // Move the bound back
            bound.translate(-obj1.getDx(), -obj1.getDy());
        }

        return collide;
    }

    public void step() {
        bound.setBounds(x, y, width, height);
    }

    public Rectangle getBound() {
        return bound;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int getDy() {
        return dy;
    }

    public int getDx() {
        return dx;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:22:39+00:00Added an answer on June 17, 2026 at 6:22 pm

    You cannot add a mouse listener to just any object type. Obj must extend java.awt.Component in order to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code, I get a compile time error: ByRef Argument type mismatch.
I get Compiler Error C2248 when i try to compile the following code: #include
In the following code, I get a compile time error because i is treated
For the attached code, I get the following compile time error : exception during
In the following code, I don't get any warning or compile error if I
I have the following code that doesn't compile. I get the error Cannot use
I use MinGW latest version to compile the following code. I get the folowing
When I compile the following code, I only see the error during Run-time which
I am trying to compile the following code and i am getting the error:
After compiling the following code in Eclipse using a Mac: import java.io.*; public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.