适配器类:实现了带有无任何内容方法的监听器接口。
适配器类的主要思想:使你可以从已经提供的适配器类中派生出自己的监听器类,仅实现自己感兴趣的方法。
- package eventhandle;
-
import java.awt.event.*;
-
import java.awt.*;
-
import java.applet.*;
-
public class AdapterDemo extends Applet{
-
public void init()
-
{
-
addMouseListener(new MyMouseAdapter(this));
-
addMouseMotionListener(new MyMouseMotionAdapter(this));
-
}
-
class MyMouseAdapter extends MouseAdapter
-
{
-
private AdapterDemo adapterdemo;
-
public MyMouseAdapter(AdapterDemo adapterdemo)
-
{
-
this.adapterdemo=adapterdemo;
-
}
-
public void mouseClicked(MouseEvent m)
-
{
-
adapterdemo.showStatus("mouse clicked");
-
}
-
}
-
class MyMouseMotionAdapter extends MouseAdapter
-
{
-
private AdapterDemo adapterdemo;
-
public MyMouseMotionAdapter(AdapterDemo adapterdemo)
-
{
-
this.adapterdemo=adapterdemo;
-
}
-
public void mouseDragged(MouseEvent m)
-
{
-
adapterdemo.showStatus("mouseDragged");
-
}
-
}
-
}
阅读(1115) | 评论(0) | 转发(0) |