1 26 27 package org.objectweb.ccm.chat.cif; 28 29 import org.objectweb.ccm.chat.*; 30 31 42 public class ClientImpl 43 extends org.objectweb.ccm.chat.ClientSessionComposition.ComponentImpl 44 implements java.awt.event.ActionListener 45 { 46 52 53 private String name_; 54 55 56 private java.awt.Frame frame_; 57 58 private java.awt.TextField text_; 59 60 private java.awt.TextArea textArea_; 61 62 public static final java.awt.Color white_ = java.awt.Color.white; 63 64 70 71 public 72 ClientImpl() 73 { 74 } 75 76 82 88 94 100 public void 101 configuration_complete() 102 throws org.omg.Components.InvalidConfiguration 103 { 104 if(name_ == null) 106 throw new org.omg.Components.InvalidConfiguration(); 107 108 if(get_context().get_connection_the_service() == null) 110 throw new org.omg.Components.InvalidConfiguration(); 111 112 frame_ = new java.awt.Frame (name_ + "'s Chat GUI"); 115 116 textArea_ = new java.awt.TextArea (); 118 textArea_.setEditable(false); 119 textArea_.setBackground(white_); 120 121 122 text_ = new java.awt.TextField ("", 1); 124 java.awt.Button button = new java.awt.Button ("Print Text"); 126 button.addActionListener(this); 127 java.awt.Panel panel = new java.awt.Panel ( 129 new java.awt.BorderLayout () 130 ); 131 System.out.println("___________________________"); 132 frame_.setLayout ( new java.awt.BorderLayout () ) ; 133 frame_.add(panel); 134 135 panel.add(textArea_,java.awt.BorderLayout.NORTH); 136 panel.add(text_,java.awt.BorderLayout.CENTER); 137 panel.add(button,java.awt.BorderLayout.SOUTH); 138 139 frame_.setSize(400,300); 140 frame_.pack(); 141 frame_.show(); 142 143 } 144 145 151 156 public void 157 ccm_remove() 158 throws org.omg.Components.CCMException 159 { 160 if(frame_!=null) 162 frame_.dispose(); 163 frame_ = null; 164 } 165 166 172 177 public void 178 name(String n) 179 { 180 name_ = n; 181 182 if (frame_ != null) 183 frame_.setTitle(name_ + "'s Client GUI"); 184 } 185 186 191 public String 192 name() 193 { 194 return name_; 195 } 196 197 198 199 205 210 public void 211 actionPerformed(java.awt.event.ActionEvent e) 212 { 213 Service service = get_context().get_connection_the_service(); 216 217 if(service == null) 219 { 220 System.err.println("The chat::Client::the_service receptacle is not set!"); 221 return; 222 } 223 224 service.display(name_ + ":" + text_.getText()); 226 227 text_.setText(""); 229 230 } 231 232 233 234 240 245 public void 246 push(TextEvent event) 247 { 248 textArea_.append(event.text + "\n"); 250 } 251 252 } 253 | Popular Tags |