• Post Reply Bookmark Topic Watch Topic
  • New Topic

mouseadapter vs mouselistener

 
madhu chakkaravarthy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if a class extends mouse adapter as well mouse listener interface what will be the output
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MouseAdapter already implements MouseListener, so there wouldn't be any difference.

MouseAdapter, and others like it, only exist to make life easy for you - you only need to override those methods you need to override instead of implementing every single one.

An example, with WindowListener. This interface has 7 methods. Suppose you only want an implementation for windowClosing. If you just implement the interface you'll have to create all 7 methods, 6 of which will have empty bodies. By extending WindowAdapter instead you'll only have to override the windowClosing method, because WindowAdapter already provides the empty body implementation for the other methods.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!