java.beans.PropertyChangeListener
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的更多相关文章
- java beans
There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...
- [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 ...
- java.lang.ClassCastException: sun.jdbc.odbc.JdbcOdbcStatement cannot be cast to java.beans.Statement
当导入的包为:import java.sql.Statement;时,无任何错误 当导入的包为:import java.beans.Statement;时,出错
- 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 ...
- ZOJ3714:Java Beans
There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...
- 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 ...
- JSP中操作Java Beans
以下内容引用自http://wiki.jikexueyuan.com/project/jsp/beans.html: JavaBean是在编写Java时专门创建的Java类,根据JavaBean AP ...
- Oracle EBS Form Builder使用Java beans创建窗体
最近有个项目,需要研究一下Oracle的E-Business Sutie(EBS),对于以前没接触此套件的我来说,简直太痛苦了.在网上找了一堆资料,试着进行Form二次开发,也遇到各类奇葩问题.目前遇 ...
- 解决java.beans.Introspector导致的内存泄漏
解决方案: 在WEB.XML 中配置监听器: <listener> <listener-class> org.springframework.web.util.Introspe ...
随机推荐
- [React Native] Dismiss the Keyboard in React Native
In this lesson you will learn how create a re-usable component that gives the user the ability to di ...
- how to deal with "no such file error or diretory" error for a new programmer in QT creator
when i try to develop a hello demo in QT creator with the code following : #include<QApplication& ...
- 阿里云部署Docker(9)----Dockerfile脚本定制镜像
本文为原创文章.转载需注明转自:http://blog.csdn.net/minimicall? viewmode=contents 技术爱好者都是比較懒的.而docker又是开发人员支持起来的.所以 ...
- JavaSript之prototype属性
近期在JavaSript进行Array操作的时候发现没有删除节点的方法.而我要实现的效果须要不断调用删除节点的方法.查找了相关资料发现能够利用prototype属性给Array添加删除节点的方法.而且 ...
- HDU 5399 Too Simple (2015年多校比赛第9场)
1.题目描写叙述:点击打开链接 2.解题思路:本题分情况讨论.比赛时候真是想的太简单了.以为就是(n!)^(cnt-1). 终于无限WA. 本题有几个特殊情况须要额外推断. 首先,假设输入的时候.有某 ...
- Vim 删除不包含指定字符串的行及统计匹配个数
Vim 删除不包含指定字符串的行及统计匹配个数 转载▼ Help :g/pattern/d 是找到pattern, 删之 :v/pattern/d 是找到非pattern, 删之 :%s/xx ...
- python 3.x 写 shell sed 替换功能
shell sed 替换功能 f1 = open('yesterday','r',encoding='utf-8') f2 = open('yesterday2','w',encoding='utf- ...
- codeforces 540 B School Marks【贪心】
题意:一共n个数,给出其中k个数,要求这n个数的中位数为y,这n个数的和不超过x,补全剩下的n-k个数 先统计给出的k个数里面比中位数小的数, 如果cnt<=n/2,说明中位数还没有出现,把这n ...
- win10 的MQTT + apache-apollo服务器使用
我的使用环境是windows10 2.下载文件目录(注意:开始看教程说直接打开bin目录下的apollo.cmd文件,闪退,原因是没有java_home环境,必须添加java环境): 3.安装好jav ...
- cmder-替代cmd
之所以选择cmder,说来话长,在学习python的过程中,由于经常通过pip命令安装包,并且在学习一些包的使用例如virtualenv,教程贴都是在终端下的命令,这使我对cmd的使用频率慢慢变多了起 ...