Skip to content

Commit f1800d9

Browse files
committed
Signed-off-by: chenhaoxiang <[email protected]>
1 parent 06c15c1 commit f1800d9

29 files changed

+323
-0
lines changed

myListenerWeb/.classpath

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_6_CONTAINER"/>
6+
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
7+
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
8+
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
9+
</classpath>

myListenerWeb/.mymetadata

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-module
3+
type="WEB"
4+
name="myListenerWeb"
5+
id="myeclipse.1471595135635"
6+
context-root="/myListenerWeb"
7+
j2ee-spec="6.0"
8+
archive="myListenerWeb.war">
9+
<attributes>
10+
<attribute name="webrootdir" value="WebRoot" />
11+
</attributes>
12+
</project-module>
13+

myListenerWeb/.project

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>myListenerWeb</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.jdt.core.javabuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
<buildCommand>
29+
<name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
30+
<arguments>
31+
</arguments>
32+
</buildCommand>
33+
<buildCommand>
34+
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
35+
<arguments>
36+
</arguments>
37+
</buildCommand>
38+
<buildCommand>
39+
<name>org.eclipse.wst.validation.validationbuilder</name>
40+
<arguments>
41+
</arguments>
42+
</buildCommand>
43+
</buildSpec>
44+
<natures>
45+
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
46+
<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
47+
<nature>org.eclipse.jdt.core.javanature</nature>
48+
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
49+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
50+
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
51+
</natures>
52+
</projectDescription>

myListenerWeb/.settings/.jsdtscope

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="WebRoot"/>
4+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
6+
<attributes>
7+
<attribute name="hide" value="true"/>
8+
</attributes>
9+
</classpathentry>
10+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
11+
<classpathentry kind="output" path=""/>
12+
</classpath>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#Fri Aug 19 16:25:38 CST 2016
2+
eclipse.preferences.version=1
3+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5+
org.eclipse.jdt.core.compiler.compliance=1.6
6+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
8+
org.eclipse.jdt.core.compiler.source=1.6
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-modules id="moduleCoreId" project-version="1.5.0">
3+
<wb-module deploy-name="myListenerWeb">
4+
<wb-resource deploy-path="/" source-path="/WebRoot"/>
5+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
6+
<property name="context-root" value="/myListenerWeb"/>
7+
<property name="java-output-path" value="/myListenerWeb/WebRoot/WEB-INF/classes"/>
8+
</wb-module>
9+
</project-modules>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<fixed facet="wst.jsdt.web"/>
4+
<installed facet="java" version="1.6"/>
5+
<installed facet="jst.web" version="3.0"/>
6+
<installed facet="wst.jsdt.web" version="1.0"/>
7+
</faceted-project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Window

myListenerWeb/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
监听器Listener解析与实例
2+
3+
监听器-就是一个实现待定接口的普通Java程序,此程序专门用于监听另外一个类的方法调用。
4+
这是使用观察者模式的。
5+
6+
什么是观察者模式:
7+
定义对象间一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知自动更新。
8+
示例:
9+
GUI编程中的addXxxxListener都是观察者模式。
10+
比如为按钮点击添加监听事件,为键盘添加监听等等…
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Class-Path:
3+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

myListenerWeb/WebRoot/WEB-INF/web.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="3.0"
3+
xmlns="http://java.sun.com/xml/ns/javaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
6+
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
7+
<display-name></display-name>
8+
<welcome-file-list>
9+
<welcome-file>index.jsp</welcome-file>
10+
</welcome-file-list>
11+
</web-app>

myListenerWeb/WebRoot/index.jsp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2+
<%
3+
String path = request.getContextPath();
4+
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5+
%>
6+
7+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
8+
<html>
9+
<head>
10+
<base href="<%=basePath%>">
11+
12+
<title>My JSP 'index.jsp' starting page</title>
13+
<meta http-equiv="pragma" content="no-cache">
14+
<meta http-equiv="cache-control" content="no-cache">
15+
<meta http-equiv="expires" content="0">
16+
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
17+
<meta http-equiv="description" content="This is my page">
18+
<!--
19+
<link rel="stylesheet" type="text/css" href="styles.css">
20+
-->
21+
</head>
22+
23+
<body>
24+
This is my JSP page. <br>
25+
</body>
26+
</html>

myListenerWeb/myListenerWeb.zip

18.5 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cn.hncu.designPattern1;
2+
3+
public class Demo {
4+
5+
public static void main(String[] args) {
6+
Person person = new Person("张三");
7+
IPersonRunListener listener = new IPersonRunListener() {
8+
@Override
9+
public void fighting() {
10+
//这里可以做很多事,不是只能输出哦
11+
//不过由于还没写Event对象,所以拿不到是谁调用的
12+
System.out.println("先做好准备工作...");
13+
}
14+
};
15+
person.addBefore(listener);
16+
17+
A a = new A();
18+
19+
person.addAfter(a);
20+
21+
person.run();
22+
}
23+
}
24+
25+
class A implements IPersonRunListener{
26+
@Override
27+
public void fighting() {
28+
//这里可以做很多事,不是只能输出哦
29+
//不过由于还没写Event对象,所以拿不到是谁调用的
30+
System.out.println("跑完了,休息休息...");
31+
}
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cn.hncu.designPattern1;
2+
3+
public class Person {
4+
private String name;
5+
private IPersonRunListener listener1;
6+
private IPersonRunListener listener2;
7+
public Person(String name) {
8+
super();
9+
this.name = name;
10+
}
11+
12+
public void run(){
13+
if(listener1!=null){
14+
listener1.fighting();
15+
}
16+
System.out.println(name+"正在跑...");
17+
if(listener2!=null){
18+
listener2.fighting();
19+
}
20+
}
21+
22+
public void addBefore(IPersonRunListener listener){
23+
this.listener1=listener;
24+
}
25+
26+
public void addAfter(IPersonRunListener listener){
27+
this.listener2=listener;
28+
}
29+
30+
}
31+
32+
interface IPersonRunListener{
33+
public void fighting();
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cn.hncu.designPattern2;
2+
3+
public class Demo {
4+
5+
public static void main(String[] args) {
6+
Person p1 = new Person("张三");
7+
Person p2 = new Person("Jack");
8+
IPersonRunListener listener = new IPersonRunListener() {
9+
@Override
10+
public void fighting(PersonEvent pe) {
11+
System.out.println(pe.getSource()+"已经跑完了...");
12+
if(pe.getName().equals("张三")){
13+
System.out.println(pe.getName()+"跑到了第一名...");
14+
}
15+
}
16+
};
17+
p1.addPersonListener(listener);
18+
p2.addPersonListener(listener);
19+
p1.run();
20+
p2.run();
21+
22+
23+
Person p3 = new Person("李四");
24+
p3.addPersonListener(new DefaultCatListener());
25+
p3.run();
26+
}
27+
}
28+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package cn.hncu.designPattern2;
2+
3+
public class Person {
4+
private String name;
5+
private IPersonRunListener listener;
6+
7+
8+
public Person(String name) {
9+
super();
10+
this.name = name;
11+
}
12+
13+
public void run(){
14+
System.out.println(name+"开始跑了..");
15+
if(listener!=null){
16+
listener.fighting(new PersonEvent(this));
17+
}
18+
}
19+
20+
public void addPersonListener(IPersonRunListener listener){
21+
this.listener=listener;
22+
}
23+
24+
public String getName(){
25+
return name;
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return "Person [name=" + name + ", listener=" + listener + "]";
31+
}
32+
33+
34+
35+
}
36+
37+
interface IPersonRunListener {
38+
public void fighting(PersonEvent pe);
39+
}
40+
41+
class PersonEvent{
42+
Person p = null;
43+
public PersonEvent(Person p) {
44+
this.p = p;
45+
}
46+
47+
public String getName(){
48+
return p.getName();
49+
}
50+
51+
public Object getSource(){
52+
return p;
53+
}
54+
}
55+
56+
//我们还可以写一个帮我们实现了接口的基本类
57+
//里面写我们通用的模板,如果我们继承这个类,我们就可以不写了。
58+
//有功能不一样的地方,我们就自己写,覆盖这个类的方法
59+
class DefaultCatListener implements IPersonRunListener {
60+
61+
@Override
62+
public void fighting(PersonEvent pe) {
63+
System.out.println("默认的动作...");
64+
}
65+
}
66+
67+

0 commit comments

Comments
 (0)