把小孩醒来时的具体情况封装成事件类

Test.java

class WakenUpEvent{

	private long time;
private String location;
private Child source; public WakenUpEvent(long time, String location, Child source) {
super();
this.time = time;
this.location = location;
this.source = source;
} public long getTime() {
return time;
} public void setTime(long time) {
this.time = time;
} public String getLocation() {
return location;
} public void setLocation(String location) {
this.location = location;
} public Child getSource() {
return source;
} public void setSource(Child source) {
this.source = source;
} } class Child implements Runnable { private Dad dad; public Child(Dad dad) {
this.dad = dad;
} public void wakeUp(){
dad.actionToWakenUp(new WakenUpEvent(System.currentTimeMillis(), "bed", this));
} @Override
public void run() {
try {
Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
}
wakeUp();
}
} class Dad { public void actionToWakenUp(WakenUpEvent e) {
System.out.println(e.getTime());
System.out.println(e.getLocation());
System.out.println(e.getSource());
System.out.println("Fedd the child");
} } public class Test { public static void main(String[] args) {
Dad d = new Dad();
Child c = new Child(d);
new Thread(c).start();
}
}

  

运行结果:

最新文章

  1. 关键帧动画:@keyframes
  2. JavaScript权威设计--JavaScript表达式与运算符(简要学习笔记五)
  3. javascript中数组concat()join()split()
  4. Java创建目录 mkdir与mkdirs的区别
  5. PROCESS STATES
  6. 关键字 base 的作用
  7. Boa练习程序2
  8. 《sort命令的k选项大讨论》-linux命令五分钟系列之二十七
  9. Spring 4.x org.springframework.http.converter.json.MappingJacksonHttpMessageConverter ClassNotFoundException:
  10. 用java写bp神经网络(二)
  11. css3滚动提示
  12. mysql----show slave status \G 说明
  13. 使用ResourceDictionary管理Logical Resources
  14. 关于 mybatis-generator自定义注释生成 使用DefaultCommentGenerator重写来完成
  15. DC3求后缀数组板子
  16. Jquery Post提交时Content-Type的不同取值详解
  17. jQuery Mobile的默认配置项具体解释,jQuery Mobile的中文配置api,jQuery Mobile的配置说明,配置大全
  18. hdoj-1068(二分图的最小点覆盖)
  19. Java KeyNote
  20. Longest Word in Dictionary through Deleting - LeetCode

热门文章

  1. C语言函数返回数组
  2. ajax 例子
  3. 容器适配器之stack
  4. python操作sqlite数据库
  5. Careercup - Microsoft面试题 - 5649647234187264
  6. 常用EXE文件反编译工具
  7. 查看javadoc
  8. 【BZOJ】【3210】花神的浇花集会
  9. sql server 时间
  10. MariaDB Galera Cluster 部署(如何快速部署 MariaDB 集群)