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

  • SEARCH
  • Home
  • 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 7880101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:03:47+00:00 2026-06-03T04:03:47+00:00

I’m currently working on a simple 2d game library for self education only. Until

  • 0

I’m currently working on a simple 2d game library for self education only.
Until know everything is working as expected.

Now I’m planning the movement and the events triggered by the ‘gameflow’ (e.g. timer) or the entities itselves. I was wondering if it is possible to have custom events like ‘EntityEventListener’ and ‘EntityMotionListener’. Then I had a look at MouseListener and its parent classes. Then I wrote for each listener a listener interface and an adapter class like this:

public interface AppEntityEventListener extends EventListener
{
    void onCreated(Event e);
    void onDeleted(Event e);
    void onStepped(Event e);
    void onSelected(Event e);
}

public abstract class AppEntityEventAdapter implements AppEntityEventListener
{
    @Override public void onCreated(Event e) { } 
    @Override public void onDeleted(Event e) { } 
    @Override public void onStepped(Event e) { } 
    @Override public void onSelected(Event e) { }
}

I’ve detected that I only can add the listeners to Components and the Entity class is not derived from a Component respectively JComponent.

I read a bit about Listeners but I don’t get the point how to deal with it as I need them for now.

Considering that my questions are now:

  • Are there any bad things about these classes?
  • How can I add these listeners the best / easiest way to my Entity class?

Thanks in advance.

EDIT:

I’ve added all the methods like you said. So now I’ve got two List objects called eventListeners and motionListeners each has its own add and remove function.

I have got a further question regarding the iteration, using the following code:

private void iterateListeners()
{
    for (Object obj : eventListeners.toArray())
    {
        AppEntityEventListener l = (AppEntityEventListener) obj;
        Event e = new Event(this, Event.ACTION_EVENT, this);

        l.onCreated(e);
        l.onDeleted(e);
        l.onSelected(e);
        l.onStepped(e);
    }

    // ... other listener ...
}

How to deal the Event at this point? Is this the right way I really have no clue … this code above is just intuitive.

  • 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-03T04:03:48+00:00Added an answer on June 3, 2026 at 4:03 am

    You can add listeners to any object you like, provided the object has a method which allows adding (and removing) a listener. Just add addXxxListener()/removeXxxListener() methods to your object.

    These methods should simply add/remove the listener to/from a collection of listeners, and the object should iterate through this collection and call the onXxx() method when appropriate.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.