001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.mina.example.udp; 021 022import java.awt.GridBagConstraints; 023import java.awt.GridBagLayout; 024import java.awt.Insets; 025 026import javax.swing.JLabel; 027import javax.swing.JPanel; 028import javax.swing.JTextField; 029import javax.swing.SwingUtilities; 030 031/** 032 * Class the represents a client connection using a JPanel 033 * 034 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 035 */ 036public class ClientPanel extends JPanel { 037 038 private static final long serialVersionUID = 1L; 039 040 private JTextField textField; 041 042 public ClientPanel(String label) { 043 super(); 044 045 setPreferredSize(MemoryMonitor.PANEL_SIZE); 046 047 setLayout(new GridBagLayout()); 048 GridBagConstraints c = new GridBagConstraints(); 049 050 c.insets = new Insets(5, 5, 5, 5); 051 c.anchor = GridBagConstraints.CENTER; 052 053 c.gridwidth = GridBagConstraints.REMAINDER; 054 add(new JLabel(label), c); 055 056 c.gridwidth = 1; 057 add(new JLabel("Memory Used : ")); 058 textField = new JTextField(10); 059 textField.setEditable(false); 060 add(textField, c); 061 } 062 063 public void updateTextField(final long val) { 064 System.out.println("New value for textfield - " + val); 065 SwingUtilities.invokeLater(new Runnable() { 066 public void run() { 067 textField.setText(String.valueOf(val)); 068 } 069 }); 070 } 071}