-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
48 lines (40 loc) · 1.08 KB
/
Copy pathClient.java
File metadata and controls
48 lines (40 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package net;
import objects.Chess;
import javax.swing.*;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
public class Client {
Socket socket;
public int port = 7103;
public String ip = null;
JFrame frame;
public static final int TAG = 1;
public Client(String ip, Integer port, JFrame frame) {
this.frame = frame;
if (ip.equals("")||ip.equals("请输入IP")){
this.ip = "localhost";
} else {
this.ip = ip;
}
if (port!=null) {
this.port = port;
}
if(joinRoom()){
JOptionPane.showMessageDialog(frame, "加入房间成功");
frame.setVisible(false);
new NetJudge(socket, TAG);
} else {
JOptionPane.showMessageDialog(frame, "加入房间失败");
}
}
private boolean joinRoom(){
try {
socket = new Socket(ip, port);
} catch (IOException e) {
JOptionPane.showMessageDialog(frame,"房间不存在");
return false;
}
return true;
}
}