-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectClient.java
More file actions
106 lines (80 loc) · 3.07 KB
/
Copy pathProjectClient.java
File metadata and controls
106 lines (80 loc) · 3.07 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import javax.swing.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
/**
* @author Abhiram Saran
* @version 25 Jan 2020
*/
public class ProjectClient {
private static Socket socket;
private static ObjectOutputStream outputStream;
private static ObjectInputStream inputStream;
public static String hostnameInput() { //don't shout at me for using GUIs I tried my best okay
return JOptionPane.showInputDialog(null, "Please enter a Hostname",
"TITLE", JOptionPane.QUESTION_MESSAGE);
}
public void createOrganiser(){ //Enter name age yadayadayada
}
public void enterStaff() { //use addStaff from Organiser parent class
}
public ArrayList<Staff> viewStaff() { //use arraylist above to show staff
ArrayList<Staff> temp = new ArrayList<>();
return temp;
//incomplete
}
public static void main(String[] args) { // may/may not have ripped this clean from the project 5 client
String host;
try {
host = hostnameInput();
} catch (NullPointerException e) {
JOptionPane.showMessageDialog(null, "Enter valid Hostname!",
"Invalid Hostname", JOptionPane.ERROR_MESSAGE);
return;
}
System.out.println(host);
int port = 0;
boolean validPort = false;
while (!validPort) {
String portString = "";
try {
portString = JOptionPane.showInputDialog(null, "Please enter a Port Number",
"TITLE", JOptionPane.QUESTION_MESSAGE);
} catch (NullPointerException e) {
JOptionPane.showMessageDialog(null, "Enter a valid Port Number!",
"Invalid Port Number", JOptionPane.ERROR_MESSAGE);
return;
}
int characterCounter = 0;
for (int i = 0; i < portString.length(); i++) {
if (!Character.isDigit(portString.charAt(i))) {
characterCounter++;
}
}
if (characterCounter > 0) {
JOptionPane.showMessageDialog(null, "Enter a valid Port Number!",
"Invalid Port Number", JOptionPane.ERROR_MESSAGE);
}
if (characterCounter == 0) {
port = Integer.parseInt(portString);
validPort = true;
}
}
System.out.println(port);
try {
socket = new Socket(host, port);
outputStream = new ObjectOutputStream(socket.getOutputStream());
inputStream = new ObjectInputStream(socket.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
private static boolean isParsable(String string) { //trash
return string.chars()
.mapToObj(Character::isDigit)
.reduce(Boolean::logicalAnd)
.orElse(Boolean.FALSE);
}
}