Java | Adapter classes

05 min read

Adapter Classes:

  • Adapter classes provide a default implementation of all methods in an event listener interface.
  • Useful when only some of the events handled by a particular event listener interface have to be processed.
  • This avoids cluttering the program with several unwanted empty methods.
  • For this, extend one of the adapter classes & create a new class which will act as event listener & implement only those events in which you are interested

 

Listener interfaces and their equivalent Adapter classes

KeyListener — KeyAdapter

MouseListener - MouseAdapter

MouseMotionListener- MouseMotionAdapter

WindowListener-   WindowAdapter

POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error