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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:50:18+00:00 2026-06-03T07:50:18+00:00

I’m trying to differentiate between listeners and adapters. Are they pretty much the same

  • 0

I’m trying to differentiate between listeners and adapters.

Are they pretty much the same but in listeners you have to implement all the methods in the interface, but with adapters you have an option to only implement the methods you need so the code is cleaners and easier to read?

I also got told that adapters enable instantiation with only one implementation and you can’t instantiate listeners, I don’t fully understand this.

Can someone please explain which one is better to use and things you can do with one but you can’t with the other?

  • 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-03T07:50:19+00:00Added an answer on June 3, 2026 at 7:50 am

    WindowListener is interface which force you to override all of the methods, while WindowAdapter is implementation of WindowListener and you only need to override the method(s) that you interest to deal with.

    WindowListener is interface which mean you cant instantiation the WindowListener, while WindowAdapter is concrete class that you can use new operator to instantiation.

    When you use WindowAdapter, the code is more clean where your class only override the method(s) that you want.
    For example:

    WindowListener

    public class CloseListener implements WindowListener {
        // im not interest  on this event, but still need to override it
        @Override
        public void windowOpened(WindowEvent e) {
    
        }
        // im not interest  on this event, but still need to override it    
        @Override
        public void windowClosing(WindowEvent e) {
    
        }
    
        @Override
        public void windowClosed(WindowEvent e) {
            System.exit(0);
    
        }
        // im not interest  on this event, but still need to override it    
        @Override
        public void windowIconified(WindowEvent e) {
    
        }
        // im not interest  on this event, but still need to override it
        @Override
        public void windowDeiconified(WindowEvent e) {
    
        }
    
    }
    

    WindowAdapter

    While using adapter the code is cleaner:

    // at JFrame class
    addWindowListener(new CloseListener());
    
    // reusable Close Listener
    public class CloseListener extends WindowAdapter {
        @Override
        public void windowClosed(WindowEvent e) {
            System.exit(0);
        }
    }
    

    Or

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
             System.exit(0);
         }
    });
    

    So I would recommend to use WindowAdapter, but not must follow. However, two of the API about the same just that WindowAdapter exists as convenience for creating listener objects.

    EDIT:

    Since WindowListener is interface, you can implement it at your JFrame subclass.

    public class MainWindow extends JFrame implements WindowListener {
        // this is ok
    }
    public class MainWindow extends JFrame, WindowAdapter {
        // this is not allow
    }
    

    But you cant do it with WindowAdapter.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
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 want to count how many characters a certain string has in PHP, but

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.