1
2
3
4
5
6
7 package com.builder.uk.watchme;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 import java.beans.PropertyChangeListener;
31 import java.beans.PropertyChangeSupport;
32
33 public class WatchMeBean implements Runnable, WatchMeBeanMBean {
34 private PropertyChangeSupport changes = new PropertyChangeSupport(this);
35
36 int count;
37 String msg;
38
39 public WatchMeBean() {
40 count = 0;
41 setMsg("Initialised");
42 }
43
44 public int getCount() {
45 return count;
46 }
47
48 public void incCount() {
49 int oldcount = count;
50 count = count + 1;
51 changes.firePropertyChange("count", oldcount, count);
52 }
53
54 public void setMsg(String msg) {
55 String oldmsg = this.msg;
56
57 this.msg = msg;
58
59 changes.firePropertyChange("msg", oldmsg, msg);
60 }
61
62 public String getMsg() {
63 return msg;
64 }
65
66 public void run() {
67 while (true) {
68 try {
69 Thread.sleep(1000);
70 } catch (InterruptedException e) {
71 }
72
73 incCount();
74 }
75 }
76
77 public void reset() {
78 int oldcount = count;
79 count = 0;
80 changes.firePropertyChange("count", oldcount, count);
81 }
82
83 public void addPropertyChangeListener(PropertyChangeListener l) {
84 changes.addPropertyChangeListener(l);
85 }
86
87 public void removePropertyChangeListener(PropertyChangeListener l) {
88 changes.removePropertyChangeListener(l);
89 }
90 }
91