java什么样的类似adapter_java中Adapter是什么概念

Adapter乃适配器,适配不协调之两者,看维基一解释:

A device or application used to achieve operative compatibility between devices that otherwise are incompatible.

He had an adapter that let him plug his phone into the car's cigarette lighter for power.

说的是手机和车载电源插座之间的适配器连接了本身不协调的两者,这就是适配器adapter的功能。

JDK DOC中对KeyAdapter的解释:

public abstract class KeyAdapter

extends

Object

An abstract adapter class for receiving keyboard events. The methods in this class are empty. This class exists as convenience for creating listener objects.

Extend this class to create a KeyEvent listener and override the methods for the events of interest. (If you implement the KeyListener 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 addKeyListener method. When a key is pressed, released, or typed, the relevant method in the listener object is invoked, and the KeyEvent is passed to it.

这里它适配了什么呢?原本如果没有KeyAdapter,那就用实现了KeyListener接口的类来作listener,这样就不得不实现许多不需要实现的方法,逻辑上是不适配的,所以KeyAdapter应运而生,适配!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值