View Javadoc

1   /**
2    * Pure Java JFC (Swing 1.1) application.
3    * This application realizes a windowing application.
4    *
5    * This file was automatically generated by
6    * Omnicore CodeGuide.
7    */
8   
9   package com.builder.uk.watchme;
10  
11  /*
12   * #%L
13   * phynixx-jmx
14   * %%
15   * Copyright (C) 2014 csc
16   * %%
17   * Licensed under the Apache License, Version 2.0 (the "License");
18   * you may not use this file except in compliance with the License.
19   * You may obtain a copy of the License at
20   * 
21   *      http://www.apache.org/licenses/LICENSE-2.0
22   * 
23   * Unless required by applicable law or agreed to in writing, software
24   * distributed under the License is distributed on an "AS IS" BASIS,
25   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26   * See the License for the specific language governing permissions and
27   * limitations under the License.
28   * #L%
29   */
30  
31  
32  import javax.swing.*;
33  import java.awt.*;
34  import java.awt.event.ActionEvent;
35  import java.awt.event.ActionListener;
36  import java.awt.event.WindowAdapter;
37  import java.awt.event.WindowEvent;
38  import java.beans.PropertyChangeEvent;
39  import java.beans.PropertyChangeListener;
40  
41  /**
42   * Frame class.
43   */
44  public class WatchMeFrame extends JFrame implements PropertyChangeListener {
45      WatchMeBean watchMeBean;
46  
47      JLabel count;
48      JLabel msg;
49  
50      public WatchMeFrame() {
51          super("WatchMe");
52  
53          this.setLayout(new GridLayout(3, 2));
54  
55          count = new JLabel("");
56          msg = new JLabel("");
57  
58          this.add(new JLabel("Count:"));
59          this.add(count);
60          this.add(new JLabel("Message:"));
61          this.add(msg);
62  
63          JButton inc = new JButton("Increment");
64  
65          this.add(inc);
66  
67          // Add window listener.
68          this.addWindowListener
69                  (
70                          new WindowAdapter() {
71                              /**
72                               * Called when window close button was pressed.
73                               */
74                              public void windowClosing(WindowEvent e) {
75                                  WatchMeFrame.this.windowClosed();
76                              }
77                          }
78                  );
79  
80          // Add button listener.
81          inc.addActionListener
82                  (
83                          new ActionListener() {
84                              public void actionPerformed(ActionEvent e) {
85                                  WatchMeFrame.this.buttonPressed();
86                              }
87                          }
88                  );
89      }
90  
91      public void setWatchMeBean(WatchMeBean watchMeBean) {
92          this.watchMeBean = watchMeBean;
93          count.setText(Integer.toString(watchMeBean.getCount()));
94          msg.setText(watchMeBean.getMsg());
95          watchMeBean.addPropertyChangeListener(this);
96      }
97  
98      protected void buttonPressed() {
99          if (watchMeBean != null) {
100             watchMeBean.incCount();
101         }
102     }
103 
104     protected void windowClosed() {
105         System.exit(0);
106     }
107 
108     public void propertyChange(PropertyChangeEvent evt) {
109         String propname = evt.getPropertyName();
110 
111         if (propname.equals("msg")) {
112             msg.setText((String) evt.getNewValue());
113         } else if (propname.equals("count")) {
114             count.setText(((Integer) evt.getNewValue()).toString());
115         }
116     }
117 
118 
119 }