diff --git a/cs654/lab5/partII/ChatFrame.java b/cs654/lab5/partII/ChatFrame.java new file mode 100644 index 0000000..d20d6c5 --- /dev/null +++ b/cs654/lab5/partII/ChatFrame.java @@ -0,0 +1,27 @@ +import java.awt.*; + +public class ChatFrame extends Frame { + + protected TextArea output; + protected TextField input; + + protected Thread listener; + + public ChatFrame (String title){ + super (title); + + setLayout (new BorderLayout ()); + add ("Center", output = new TextArea ()); + output.setEditable (false); + add ("South", input = new TextField ()); + + pack (); + show (); + input.requestFocus (); + } + + public static void main (String args[]) { + new ChatFrame("Chat "); + } +} + diff --git a/cs654/lab5/partII/EnterListener.java b/cs654/lab5/partII/EnterListener.java new file mode 100644 index 0000000..af0c5ef --- /dev/null +++ b/cs654/lab5/partII/EnterListener.java @@ -0,0 +1,19 @@ +import java.awt.event.*; + +public class EnterListener extends KeyAdapter { + + ChatClient client; + ChatFrame gui; + + public EnterListener (ChatClient client, ChatFrame gui) { + this.client = client; + this.gui = gui; + } + + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + client.sendTextToChat(gui.input.getText()); + gui.input.setText(""); + } + } +}