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. ztree实现根节点单击事件,显示节点信息

    这段时间在维护公司的项目,去年做的项目里面有ztree树的例子,想起之前还没有开始写博客,一些知识点也无从找起,要新加一个右击节点事件,折腾了半天,其中也包含了一些知识点,稍稍做了一些demo. zT ...

  2. 物理读之LRU(近期最少被使用)的深入解析

    转载请注明出处: http://blog.csdn.net/guoyjoe/article/details/38264883 一组LRU链表包含LRU主链.LRU辅助链.LRUW主链,LRUW辅助链, ...

  3. 多线程02---pThread简单介绍

    1.简单介绍 pthread 是属于 POSIX 多线程开发框架. 它是c语言提供的一个跨平台的多线程解决方式.因为其在iOS编程中,操作比較麻烦.一般不用,这里介绍只作为了解. 2.pthread的 ...

  4. Cube Simulation zoj3429 模拟

    Description Here's a cube whose size of its 3 dimensions are all infinite. Meanwhile, there're 6 pro ...

  5. Java排序之直接选择排序

    public class SelectSort { public static void selectSort(int [] a){ int min; int temp; if(a==null || ...

  6. nyoj--1233--差值(贪心模拟+大数)

    差值 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 输入一个整数数组,将它们连接起来排成一个数,找出能排出的所有数字中最大,最小的两个,输出两个数的差值.例如输入数组{ ...

  7. 41.AngularJS 服务(Service)

    转自:https://www.cnblogs.com/best/tag/Angular/ 什么是服务? 在 AngularJS 中,服务是一个函数或对象,可在你的 AngularJS 应用中使用. A ...

  8. [洛谷P1169] [ZJOI2007] 棋盘制作 解题报告(悬线法+最大正方形)

    题目描述 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个 8×8 大小的黑白相间的方阵,对应八八六十四卦,黑白对应阴阳. 而我 ...

  9. Frame Stacking ZOJ 1083,poj 1128

    Frame Stacking Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4034   Accepted: 1352 De ...

  10. Pickling

    Pickle translates almost any type of object into a string. pickle.dumps takes an object as a paramet ...