Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Listener and adapter class  RSS feed

 
sun moon
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i can write code for a mouse listener like below
b1.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
}
})
because MouseAdapter is a Adapter class ok.
But my question is addMouseListener argument type is MouseListener. but i m sending MouseAdapter as argument.
How it works pls explain me.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MouseAdapter implements MouseListener, thus MouseListener is the supertype of MouseAdapter. Everywhere you need a MouseListener you can provide a MouseAdapter as well, as an MouseAdapter "is a" MouseListener (inheritance relation).
regards
Chantal
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!