Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

mouseadapter vs mouselistener  RSS feed

 
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: 20904
81
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!