copied ExitListener from partI, filled in ?'s
git-svn-id: svn://anubis/gvsu@19 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
e22b39232c
commit
10bf3e096d
@ -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);
|
||||
|
15
cs654/lab5/partII/ExitListener.java
Normal file
15
cs654/lab5/partII/ExitListener.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user