import java.awt.*; import java.awt.event.*; public class Dummy extends Frame implements ActionListener, ItemListener, WindowListener { public void actionPerformed(ActionEvent e){ // send button pressed -- pretend to send the text traffic.append("\n\n" // first a blank line, then + handle.getText() + ": " // identify sender, + msg.getText()); // and then add message msg.setText(""); // clear out the message area } public void itemStateChanged(ItemEvent e){ // channel changed -- clear traffic area traffic.setText(""); } private TextField handle; private Choice channel; private TextArea traffic; private TextArea msg; Dummy(){ setLayout(new BorderLayout()); Panel top = new Panel(); top.add(new Label("Handle:")); handle = new TextField(10); handle.setText(System.getProperty("user.name")); top.add(handle); top.add(new Label("Channel:")); channel = new Choice(); channel.add("Chat 1"); channel.add("Chat 2"); channel.addItemListener(this); top.add(channel); add(top, "North"); traffic = new TextArea("", 20, 40, TextArea.SCROLLBARS_VERTICAL_ONLY); traffic.setEditable(false); add(traffic, "Center"); Panel bottom = new Panel(); bottom.setLayout(new BorderLayout()); Panel bottomTop = new Panel(); bottomTop.add(new Label("Type your message here:")); bottom.add(bottomTop, "North"); msg = new TextArea("", 5, 40, TextArea.SCROLLBARS_VERTICAL_ONLY); bottom.add(msg, "Center"); Panel bottomBottom = new Panel(); Button send = new Button("Send"); send.addActionListener(this); bottomBottom.add(send); bottom.add(bottomBottom, "South"); add(bottom, "South"); setTitle("Chat"); setSize(400, 500); addWindowListener(this); show(); } public void windowClosing(WindowEvent e){ System.exit(0); } public void windowActivated(WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowOpened(WindowEvent e){} public static void main(String[] args){ new Dummy(); } }