Java中adapter适配器_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Java中adapter适配器

Java中adapter适配器

 2018/10/18 9:45:44  andrew7676  程序员俱乐部  我要评论(0)
  • 摘要:1.Java中adapter适配器适配器adapter实现了全部接口的方法,并且是空实现。importjava.awt.BorderLayout;importjava.awt.Frame;importjava.awt.Label;importjava.awt.TextField;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;publicclassTwoListenAdapter
  • 标签:Java
1. Java中adapter适配器
class="java">
适配器adapter实现了全部接口的方法,并且是空实现。

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class TwoListenAdapter {
    private Frame frame;
    private TextField textField;
    public void go(){
        frame = new Frame("Two Listeners Example");
        frame.add(new Label("click"), BorderLayout.NORTH);
        textField = new TextField(30);
        frame.add(textField, BorderLayout.SOUTH);
        frame.addMouseListener(new MyAdapter());
        frame.setSize(300, 200);
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        TwoListen two = new TwoListen();
        two.go();
    }
}
class MyAdapter extends MouseAdapter{
    @Override
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
        String str = "The mouse has entered the Frame";
        System.out.println(str);
    }
    @Override
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub
        String str = "The mouse has exited the Frame";
        System.out.println(str);
    }
}
上一篇: Java中观察者模式(Observer) 下一篇: 没有下一篇了!
发表评论
用户名: 匿名