copied ExitListener from partI, filled in ?'s

git-svn-id: svn://anubis/gvsu@19 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-02-17 22:28:20 +00:00
parent e22b39232c
commit 10bf3e096d
2 changed files with 23 additions and 8 deletions

View File

@ -32,12 +32,12 @@ public class ChatClient {
// waiting for and receiving messages
while (true) {
byte[] buffer = new byte[1000];
?
?
String message = new String(datagram.getData());
gui.output.append(message);
for (;;) {
byte[] buffer = new byte[1000];
DatagramPacket datagram = new DatagramPacket(buffer, buffer.length);
socket.receive(datagram);
String message = new String(datagram.getData());
gui.output.append(message);
}
} catch (IOException e) {
e.printStackTrace();
@ -47,9 +47,9 @@ public class ChatClient {
public void sendTextToChat(String message) {
message = name+": "+message+"\n";
byte[] buf = (message).getBytes();
?
DatagramPacket dg = new DatagramPacket(buf, buf.length);
try {
?
socket.send(dg);
}
catch (IOException ex) {
System.out.println(ex);

View File

@ -0,0 +1,15 @@
import java.awt.event.*;
public class ExitListener extends WindowAdapter {
ChatClient client;
public ExitListener(ChatClient client) {
this.client = client;
}
public void windowClosing(WindowEvent e) {
client.disconnect();
System.exit(0);
}
}