(七)GUI和AWT事件模型
更新时间:2023-05-25 07:39:01 阅读量: 实用文档 文档下载
- 七归和八归的珠算打法推荐度:
- 相关推荐
AWT事件模型
GUI AWT Event Model
GUI Graphic User Interface
B/S Server HTTP
Server
C/S
AWT (Abstract Window Tookit)
SWING
1 JFrame, JPanel
2
3
4
“
Container Component Component ’
Frame BorderLayout
Panel Panel Frame FlowLayout
AWT
Mother
Mother 6 00
AWT事件模型
JDK
1 EventSource
2 EventObject
3 EventListener
java.util.EeventObject
java.util.EventListener
class Mother {//
private List list = new ArrayList();
//
public void addHomeWorkListener(HomeWorkListener hwl) {
list.add(hwl);
}
//
public void removeHomeWorkListener(HomeWorkListener hwl) {
list.remove(hwl);
}
AWT事件模型
public void notify() { //
//6 O CLOLK
HomeWorkEvent event = new HomeWorkEvent(this);
Iterator it = list.iterator();
while(it.hasNext()) {
HomeWorkListener h = (HomeWorkListener)it.next();
h.homework();
}
}
class HomeWorkEvent extends EventObject{ //
public HomeWorkEvent(Object o) {
super(o);
}
}
interface HomeWorkListener extends EventListener{ //
void homework(HomeWorkEvent o);
}
class XiaoQiang implements HomeWorkListener { // 1
public void homework(HomeWorkEvent o) {
//
}
}
class XiaoMing implements HomeWorkListener {// 2
public void homework(HomeWorkEvent o) {
//
}
}
class XiaoFend implements HomeWorkListener { // 3
public void homework(HomeWorkEvent o) {
//
}
}
XXXEvent HomeWorkEvent
XXXListener HomeWorkListener
getSource()
1 Gril 1 3 5 7 9 (Boy) Boy 2 4 6 8 10 Boy
AWT事件模型
1 Gril
2 EmotionEvent extends EventObject
3 EmotionListener
4 Boy
Coding:
publicclass Gril {//
private Stringname;
private Listlist =new ArrayList();//
public Gril(String name) {
= name;
}
public String getName() {
returnname;
}
/***************************************************
*
*@parame:
*/
publicvoid addEmotionListener(EmotionListener e) {
list.add(e);
}
/*********************************************************
*
*@parame
*/
publicvoid removeEmotionListener(EmotionListener e) {
list.remove(e);
}
//
publicvoid fire() {
EmotionEvent event =new EmotionEvent(this);
for (int i = 0; i < 10; i++) {
if(i % 2 == 0 ) {
Iterator it =list.iterator();
while(it.hasNext()) {
EmotionListener el =
(EmotionListener)it.next();
el.whatCanIdoWhenHappy(event);
}
}else {
Iterator it =list.iterator();
while(it.hasNext()) {
EmotionListener el =
AWT事件模型
(EmotionListener)it.next();
el.whatCanIdoWhenSad(event);
}
}
}
}
}
//
publicclass EmotionEventextends EventObject {
public EmotionEvent(Object o) {
super(o);
}
}
//
publicinterface EmotionListenerextends EventListener {
void whatCanIdoWhenHappy(EmotionEvent e);
void whatCanIdoWhenSad(EmotionEvent e);
}
// : Boy
publicclass Boyimplements EmotionListener {
private Stringname;
public Boy(String name) {
= name;
}
public String getName() {
returnname;
}
publicvoid whatCanIdoWhenHappy(EmotionEvent e) {
Object o = e.getSource();
Gril g = (Gril)o;
System.out.println(name+" said to "+g.getName()+", youhappy,I am happy");
}
publicvoid whatCanIdoWhenSad(EmotionEvent e) {
Object o = e.getSource();
Gril g = (Gril)o;
System.out.println(name+" said to "+g.getName()+", yousad,I am so sad.");
}}
Time , 2006 Olympics WorldCup Olympics WorldCup
AWT事件模型
Coding:
class Time { //
private List lt = new ArrayList();//
private int year; //
public int getYear() { return year; }
public void addTimeListener(TimeListener t) {
lt.add(t);
}
public void removeTimeListener(TimeListener t) {
lt.remove(t);
}
public void action() {
TimeEvent event = new TimeEvent(this);
for(int i=2006;i<=3000;i++) {
this.year = i; //
Iterator it = lt.iterator();
while(it.hasNext()) {
TimeListener tl = (TimeListener)it.next();
// disp()
tl.disp(event);
}
}
}
}
//
class TimeEvent extends EventObject {
public TimeEvent(Object o) {
super(o);
}
}
//
interface TimeListener extends EventListener {
void disp(TimeEvent event);
}
// 1
class Olympics implements TimeListener {
public void disp(TimeEvent event) {
Time t = (Time)event.getSource();
if(t.getYear() % 4 == 0 ){
System.out.println(t.getYear()+” ”);
}
}
}
// 2
AWT事件模型
class WorldCup implements TimeListener {
public void disp(TimeEvent event) {
Time t = (Time)event.getSource();
if(t.getYear() % 4 == 2 ) {
System.out.println(t.getYear()+” ”);
}
}
}
1 N 7
7
(Steven Ye)mailto: leton.ye@
正在阅读:
(七)GUI和AWT事件模型05-25
宽容是什么排比句02-21
经典总结电磁感应(知识点 例题精析):专题3:电磁感07-03
神奇的伞作文600字06-21
牛顿第二定律教学设计05-13
七年级历史下册第一单元隋唐时期:繁荣与开放的时代第3课盛唐气象教案新人教版05-02
海南教师资格面试真题及解析:综合分析类题型(十五)05-08
我国中部地区对外贸易发展对策分析12-06
后浇带的作用及做法2012.2.2003-10
教师教学计划_工作计划.doc04-26
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- 模型
- 事件
- GUI
- AWT