import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport; public class DemoBeans { private String demoName;
private String Version;
PropertyChangeSupport listeners = new PropertyChangeSupport(this); public DemoBeans() {
demoName = "initValue";
Version="v1000";
} public String getDemoName() {
return demoName;
} public void setDemoName(String demoName) {
String oldValue = this.demoName;
this.demoName = demoName;
//发布监听事件
firePropertyChange("demoName", oldValue, demoName); } public void setDemoVersion(String demoVersion) {
String oldVersion = this.Version;
this.Version = demoVersion;
//发布监听事件
firePropertyChange("demoVersion", oldVersion, demoVersion); }
public void addPropertyChangeListener(PropertyChangeListener listener) {
listeners.addPropertyChangeListener(listener);
} public void removePropertyChangeListener(PropertyChangeListener listener){
listeners.addPropertyChangeListener(listener);
} /**
* 触发属性改变的事件
*/
protected void firePropertyChange(String prop, Object oldValue, Object newValue) {
listeners.firePropertyChange(prop, oldValue, newValue);
}
public static void main(String[] args) {
DemoBeans beans = new DemoBeans(); beans.addPropertyChangeListener(
new PropertyChangeListener(){
public void propertyChange(PropertyChangeEvent evt) {
if(evt.getPropertyName().equals("demoVersion")){
System.out.println("version_OldValue:"+evt.getOldValue());
System.out.println("version_NewValue:"+evt.getNewValue());
System.out.println("version_tPropertyName:"+evt.getPropertyName());
}
else
{
System.out.println("name_OldValue:"+evt.getOldValue());
System.out.println("name_NewValue:"+evt.getNewValue());
System.out.println("name_tPropertyName:"+evt.getPropertyName());
} }}); beans.setDemoName("test");
beans.setDemoVersion("v2000"); }
}

java.beans.PropertyChangeListener的更多相关文章

  1. java beans

    There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...

  2. [ACM_水题] ZOJ 3714 [Java Beans 环中连续m个数最大值]

    There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...

  3. java.lang.ClassCastException: sun.jdbc.odbc.JdbcOdbcStatement cannot be cast to java.beans.Statement

    当导入的包为:import java.sql.Statement;时,无任何错误 当导入的包为:import java.beans.Statement;时,出错

  4. SQLException: com.mchange.v2.c3p0.ComboPooledDataSource [ java.beans.IntrospectionException: java.lang.reflect.InvocationTargetException [numThreadsAwaitingCheckoutDefaultUser] ] has been closed()

    问题:Could not get JDBC Connection; nested exception is java.sql.SQLException: com.mchange.v2.c3p0.Com ...

  5. ZOJ3714:Java Beans

    There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...

  6. Freemaker的java.beans.IntrospectionException: type mismatch between read and write methods

    引言:freemaker在特定的spring以及jdk下的问题解决路径. 环境描述 spring 3.1.1, jdk1.8u80, freemake 2.3.19 错误信息描述: 严重: Excep ...

  7. JSP中操作Java Beans

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/beans.html: JavaBean是在编写Java时专门创建的Java类,根据JavaBean AP ...

  8. Oracle EBS Form Builder使用Java beans创建窗体

    最近有个项目,需要研究一下Oracle的E-Business Sutie(EBS),对于以前没接触此套件的我来说,简直太痛苦了.在网上找了一堆资料,试着进行Form二次开发,也遇到各类奇葩问题.目前遇 ...

  9. 解决java.beans.Introspector导致的内存泄漏

    解决方案: 在WEB.XML 中配置监听器: <listener> <listener-class> org.springframework.web.util.Introspe ...

随机推荐

  1. Python: Json串反序列化为自定义类对象

    最近刚接触到python,就想到了如何反序列化json串.网上找了一下,大部分都是用json模块反序列化为python数据结构(字典和列表).如果对json模块不了解的参考菜鸟教程.然后我在此基础上将 ...

  2. 紫书 例题8-15 UVa 12174 (滑动窗口)

    这道题就是给你一n长序列, 然后把这个序列按顺序分成很多段, 每段长s(最前面可以小于s, 只有第一段的后半段, 最后面也同样, 只有最后一段的前半段), 然后要求是每一段里面没有重复的数, 问你有几 ...

  3. CAD二次开发(01)-绘制直线

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. LightOJ - 1132 Summing up Powers 矩阵高速幂

    题目大意:求(1^K + 2^K + 3K + - + N^K) % 2^32 解题思路: 借用别人的图 能够先打表,求出Cnm,用杨辉三角能够高速得到 #include<cstdio> ...

  5. PHP join() 函数

    PHP join() 函数 实例 把数组元素组合为一个字符串: <?php $arr = array('Hello','World!','I','love','Shanghai!'); echo ...

  6. centos 服务器配置注意项

    Mysql 出现Table‘xxx’is read only问题 Mysql数据库在由Mssql数据库导入数据文件后出现“ERROR 1036 (HY000): Table 'xxxx' is rea ...

  7. BZOJ 2115 DFS+高斯消元

    思路: 先搞出来所有的环的抑或值 随便求一条1~n的路径异或和 gauss消元找异或和最大 贪心取max即可 //By SiriusRen #include <cstdio> #inclu ...

  8. 使用tinyxml2库解析xml

    tinyxml2简介 tinyxml2是c++编写的轻量级的xml解析器,而且是开放源代码的,在一些开源的游戏引擎中用的比较多.源码托管在github上. 源码地址:https://github.co ...

  9. [ Git ] [ GitHub ] 如何刪除自己github上面的Repository-轉載

    http://www.winwu.cc/2013/03/githubrepository.html

  10. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(4)

    2.4 调整检查点和XLOG 目前为止,这一章已经提供深入洞察PostgreSQL如何写入数据,一般来说,XLOG是用来干什么的.考虑到这方面的知识,我们现在可以继续并学习我们能做些什么来使我们的数据 ...