日期:2014-05-20  浏览次数:21003 次

public abstract class WindowAdapter 为什么要定义成抽象类?
public   abstract   class   WindowAdapter   为什么要定义成抽象类?它都已经实现了   监听器的所有抽象方法,而且继承这适配器也可以不用覆盖他的方法。那在这里定义为抽象类有什么意义?

------解决方案--------------------
因为WindowAdapter的监听器接口里面有好多方法,但是我们一般用不了那么多,却要都实现他们,很累.java就提供一个WindowAdapter来给大家用,大家继承WindowAdapter后实现自己用的方法就行了,其他的就不用管了!
------解决方案--------------------
个人认为,java源程序编写者是为了防止直接对这个类生成对象(因为这样做是没有意义的,没有实现任何功能)而把它声明为抽象类的,要对它进行继承,再实现部分方法。(当然,你也可以不实现。。。。。)
------解决方案--------------------
An abstract adapter class for receiving mouse events. The methods in this class are empty. This class exists as convenience for creating listener objects.

Mouse events let you track when a mouse is pressed, released, clicked, moved, dragged, when it enters a component, when it exits and when a mouse wheel is moved.

Extend this class to create a MouseEvent (including drag and motion events) or/and MouseWheelEvent listener and override the methods for the events of interest. (If you implement the MouseListener, MouseMotionListener interface, you have to define all of the methods in it. This abstract class defines null methods for them all, so you can only have to define methods for events you care about.)

Create a listener object using the extended class and then register it with a component using the component 's addMouseListener addMouseMotionListener, addMouseWheelListener methods. The relevant method in the listener object is invoked and the MouseEvent or MouseWheelEvent is passed to it in following cases:
这个是api对于mouseadapter的描述,其实不声明为抽象类也是可以的,个人感觉是为了,提醒这个类是用来被继承的。
------解决方案--------------------
如果不声明为抽象类型,就可以直接new一个实例出来,这样做也没有任何含义
如果里面有抽象的方法的话,我们在extends这个类的时候还得把这些方法一一实现,不管自己用得着用不着,比较麻烦,我想这个是为了方便开发者所以实现了里面所有的方法而没有抽象的方法吧。