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 7860493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:18:40+00:00 2026-06-02T22:18:40+00:00

I was wondering how it would be possible to create my own listener for

  • 0

I was wondering how it would be possible to create my own listener for something, and to be able to use it just like any other listener, ex.

public interface Listener {

    public void onListen(Event e);

}

And then this in my class

public class test implements Listener {

    Object.add(new Listener() { 

        @Override
        public void onListen(Event e) {

        }
    });
}

I guess what i’m really asking also is where do I define how to check if something happens pertaining to the listener that I create?

If any of this doesn’t make sense, please tell me and I will clarify it.

If at best this makes no sense to you, i’ll try this. How would I make a listener to check if the selected option in a combobox has changed to a different option. I don’t actually need a combobox listener though, that was just an example.

  • 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-02T22:18:44+00:00Added an answer on June 2, 2026 at 10:18 pm

    Here is a short example:

        private static class Position {
        }
    
        private static class Ball {
            private ArrayList<FootballObserver> observers = new ArrayList<FootballObserver>();
            private Position ballPosition = new Position();
    
            public void registerObserver(FootballObserver observer) {
                observers.add(observer);
            }
    
            public void notifyListeners() {
                for(FootballObserver observer : observers) {
                    observer.notify(ballPosition);
                }
            }
    
            public void doSomethingWithFootballPosition() {
                //bounce etc
                notifyListeners();
            }
        }
    
        private static interface FootballObserver {
            void notify(Position ball);
        }
    
        private static class Player implements FootballObserver {
            public void notify(Position ball) {
                System.out.println("received new ball position");
            }
        }
    
        public static void main(String... args) {
            FootballObserver player1 = new Player();
            Ball football = new Ball();
            football.registerObserver(player1);
            football.doSomethingWithFootballPosition();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if it would be possible to do this: $var = '$something
Hey, I'm just wondering if it would be possible to convert videos to mp3
I was just wondering, for an LDAP structure, would it be possible for a
Hey im just wondering what would be the best collection to use when creating
Suppose I need to create my own small DSL that would use Python to
I am just wondering if anyone would be able to advise me how should
So I was wondering if something like this is possible: I am a program,
I was wondering if it would be possible to create a window using SWT
I was wondering if it would be possible to create a C++ environment variable
Hi I was wondering if it would be possible with the GWTP, create Presenters

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.