View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.example.udp;
21  
22  import java.awt.GridBagConstraints;
23  import java.awt.GridBagLayout;
24  import java.awt.Insets;
25  
26  import javax.swing.JLabel;
27  import javax.swing.JPanel;
28  import javax.swing.JTextField;
29  import javax.swing.SwingUtilities;
30  
31  /**
32   * Class the represents a client connection using a JPanel
33   *
34   * @author The Apache MINA Project (dev@mina.apache.org)
35   */
36  public class ClientPanel extends JPanel {
37  
38      private static final long serialVersionUID = 1L;
39  
40      private JTextField textField;
41  
42      public ClientPanel(String label) {
43          super();
44  
45          setPreferredSize(MemoryMonitor.PANEL_SIZE);
46  
47          setLayout(new GridBagLayout());
48          GridBagConstraints c = new GridBagConstraints();
49  
50          c.insets = new Insets(5, 5, 5, 5);
51          c.anchor = GridBagConstraints.CENTER;
52  
53          c.gridwidth = GridBagConstraints.REMAINDER;
54          add(new JLabel(label), c);
55  
56          c.gridwidth = 1;
57          add(new JLabel("Memory Used : "));
58          textField = new JTextField(10);
59          textField.setEditable(false);
60          add(textField, c);
61      }
62  
63      public void updateTextField(final long val) {
64          System.out.println("New value for textfield - " + val);
65          SwingUtilities.invokeLater(new Runnable() {
66              public void run() {
67                  textField.setText(String.valueOf(val));
68              }
69          });
70      }
71  }