Skip to content

Commit 2f0e596

Browse files
committed
Make public
1 parent 6d5ad87 commit 2f0e596

File tree

14 files changed

+1292
-0
lines changed

14 files changed

+1292
-0
lines changed

A2.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

readme.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
run with argument
2+
3+
-Djava.rmi.server.codebase=file:"D:\Assignments\COMP90015\A2\out\production\A2\"
4+
5+
for both client and server
6+
run rmiregistry in same directory

src/WhiteBoardClient/Client.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Benjamin Yi - 1152795
2+
3+
package WhiteBoardClient;
4+
5+
import remote.IClientCallback;
6+
import remote.IRemoteWhiteBoard;
7+
8+
import java.rmi.RemoteException;
9+
import java.rmi.registry.LocateRegistry;
10+
import java.rmi.registry.Registry;
11+
import java.rmi.server.UnicastRemoteObject;
12+
13+
/**
14+
* The main class for the WhiteBoardClient package.
15+
* Takes server ip, port number, and username as inputs.
16+
* Starts up the GUI if connection is successful.
17+
*/
18+
19+
public class Client extends UnicastRemoteObject {
20+
21+
protected Client() throws RemoteException {}
22+
23+
public static void main(String[] args) {
24+
25+
if (args.length != 3) {
26+
System.err.println("Please enter two arguments (Server IP, Server port number, username)");
27+
System.exit(0);
28+
}
29+
30+
int port = Integer.parseInt(args[1]);
31+
32+
// Sanity check port number on start-up
33+
if (port < 1024 || port > 65535) {
34+
System.err.println("Please enter a port number between 1024 and 65535.");
35+
System.exit(0);
36+
}
37+
38+
try {
39+
40+
// Connect to RMI registry
41+
Registry registry = LocateRegistry.getRegistry(args[0], port);
42+
IRemoteWhiteBoard remoteWhiteBoard = (IRemoteWhiteBoard) registry.lookup("WhiteBoardServer");
43+
44+
ClientGUI client = new ClientGUI(remoteWhiteBoard);
45+
IClientCallback clientCallbackServant = new ClientCallbackServant(args[2], client);
46+
System.out.println("Connecting to server ...");
47+
client.setServant(clientCallbackServant);
48+
49+
client.pack();
50+
client.setVisible(true);
51+
52+
} catch (Exception e) {
53+
System.err.println("Could not connect to server.");
54+
}
55+
56+
}
57+
58+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Benjamin Yi - 1152795
2+
3+
package WhiteBoardClient;
4+
5+
import remote.IClientCallback;
6+
import remote.IShape;
7+
8+
import java.rmi.RemoteException;
9+
import java.rmi.server.UnicastRemoteObject;
10+
import java.util.ArrayList;
11+
import java.util.Objects;
12+
13+
/**
14+
* Client interface with RMI server.
15+
* Passes messages through to the GUI.
16+
*/
17+
public class ClientCallbackServant extends UnicastRemoteObject implements IClientCallback {
18+
private ClientGUI clientGUI;
19+
private Integer id = null;
20+
private String username;
21+
22+
protected ClientCallbackServant(String username, ClientGUI clientGUI) throws RemoteException {
23+
this.clientGUI = clientGUI;
24+
this.username = username;
25+
}
26+
27+
public String getUsername() {
28+
return username;
29+
}
30+
31+
public String getFullUsername() {
32+
return username + "#" + id;
33+
}
34+
35+
public void setId(Integer id) {
36+
this.id = id;
37+
}
38+
39+
public Integer getId() {
40+
return id;
41+
}
42+
43+
public void updateWhiteBoard(ArrayList<IShape> shapeList) throws RemoteException {
44+
clientGUI.updateWhiteBoard(shapeList);
45+
}
46+
47+
public void updateMessageBoard(ArrayList<String> messageList) throws RemoteException {
48+
clientGUI.updateMessageBoard(messageList);
49+
}
50+
51+
public void updatePeerList(ArrayList<String> peerList) throws RemoteException {
52+
clientGUI.updatePeerList(peerList);
53+
}
54+
55+
public boolean notifyNewPeer(IClientCallback c) throws RemoteException {
56+
return clientGUI.notifyNewPeer(c);
57+
}
58+
59+
public void notifyFailure() throws RemoteException {
60+
clientGUI.notifyFailure();
61+
}
62+
63+
public void notifyKick() throws RemoteException {
64+
clientGUI.notifyKick();
65+
}
66+
67+
public void notifyKill() throws RemoteException {
68+
clientGUI.notifyKill();
69+
}
70+
71+
@Override
72+
public boolean equals(Object o) {
73+
if (this == o) return true;
74+
if (o == null || getClass() != o.getClass()) return false;
75+
if (!super.equals(o)) return false;
76+
ClientCallbackServant that = (ClientCallbackServant) o;
77+
return id.equals(that.id) &&
78+
clientGUI.equals(that.clientGUI) &&
79+
username.equals(that.username);
80+
}
81+
82+
@Override
83+
public int hashCode() {
84+
return Objects.hash(super.hashCode(), clientGUI, id, username);
85+
}
86+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="WhiteBoardClient.ClientGUI">
3+
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="1448" height="400"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<grid id="10e6c" binding="WhiteBoard" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
12+
<margin top="0" left="0" bottom="0" right="0"/>
13+
<constraints>
14+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
15+
<preferred-size width="1000" height="800"/>
16+
</grid>
17+
</constraints>
18+
<properties>
19+
<background color="-1"/>
20+
</properties>
21+
<border type="none"/>
22+
<children>
23+
<component id="1c8a9" class="javax.swing.JTextField" binding="textField" custom-create="true">
24+
<constraints>
25+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
26+
<preferred-size width="1000" height="-1"/>
27+
</grid>
28+
</constraints>
29+
<properties>
30+
<background color="-1"/>
31+
<editable value="false"/>
32+
<enabled value="false"/>
33+
</properties>
34+
</component>
35+
</children>
36+
</grid>
37+
<toolbar id="33d38">
38+
<constraints>
39+
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
40+
<preferred-size width="-1" height="20"/>
41+
</grid>
42+
</constraints>
43+
<properties>
44+
<floatable value="false"/>
45+
</properties>
46+
<border type="none"/>
47+
<children>
48+
<component id="6b754" class="javax.swing.JRadioButton" binding="lineRadioButton" default-binding="true">
49+
<constraints/>
50+
<properties>
51+
<selected value="true"/>
52+
<text value="Line"/>
53+
</properties>
54+
</component>
55+
<component id="fdb5a" class="javax.swing.JRadioButton" binding="circleRadioButton" default-binding="true">
56+
<constraints/>
57+
<properties>
58+
<text value="Circle"/>
59+
</properties>
60+
</component>
61+
<component id="e5242" class="javax.swing.JRadioButton" binding="ovalRadioButton" default-binding="true">
62+
<constraints/>
63+
<properties>
64+
<hideActionText value="false"/>
65+
<text value="Oval"/>
66+
</properties>
67+
</component>
68+
<component id="8a9bd" class="javax.swing.JRadioButton" binding="rectangleRadioButton" default-binding="true">
69+
<constraints/>
70+
<properties>
71+
<text value="Rectangle"/>
72+
</properties>
73+
</component>
74+
<component id="ab259" class="javax.swing.JRadioButton" binding="textRadioButton" default-binding="true">
75+
<constraints/>
76+
<properties>
77+
<text value="Text"/>
78+
</properties>
79+
</component>
80+
<component id="c5008" class="javax.swing.JToolBar$Separator">
81+
<constraints/>
82+
<properties/>
83+
</component>
84+
<component id="2aa3e" class="javax.swing.JLabel">
85+
<constraints/>
86+
<properties>
87+
<text value="Colour "/>
88+
</properties>
89+
</component>
90+
<component id="53457" class="javax.swing.JButton" binding="colourButton" default-binding="true">
91+
<constraints/>
92+
<properties>
93+
<background color="-16777216"/>
94+
<text value=""/>
95+
</properties>
96+
</component>
97+
</children>
98+
</toolbar>
99+
<grid id="3c147" binding="chatPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
100+
<margin top="0" left="0" bottom="0" right="0"/>
101+
<constraints>
102+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
103+
<minimum-size width="250" height="-1"/>
104+
<preferred-size width="250" height="-1"/>
105+
</grid>
106+
</constraints>
107+
<properties/>
108+
<border type="none"/>
109+
<children>
110+
<component id="fed69" class="javax.swing.JTextField" binding="messageBox">
111+
<constraints>
112+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="2" fill="1" indent="0" use-parent-layout="false">
113+
<minimum-size width="150" height="25"/>
114+
<preferred-size width="150" height="25"/>
115+
</grid>
116+
</constraints>
117+
<properties>
118+
<background color="-13355980"/>
119+
<foreground color="-2894893"/>
120+
</properties>
121+
</component>
122+
<scrollpane id="47bf4">
123+
<constraints>
124+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
125+
</constraints>
126+
<properties>
127+
<horizontalScrollBarPolicy value="31"/>
128+
</properties>
129+
<border type="none"/>
130+
<children>
131+
<component id="3f833" class="javax.swing.JTextPane" binding="chatBox">
132+
<constraints/>
133+
<properties>
134+
<background color="-13355980"/>
135+
<editable value="false"/>
136+
<foreground color="-2894893"/>
137+
</properties>
138+
</component>
139+
</children>
140+
</scrollpane>
141+
</children>
142+
</grid>
143+
<component id="2fc1f" class="javax.swing.JTextPane" binding="peerListPane">
144+
<constraints>
145+
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
146+
<preferred-size width="150" height="50"/>
147+
</grid>
148+
</constraints>
149+
<properties>
150+
<editable value="false"/>
151+
</properties>
152+
</component>
153+
</children>
154+
</grid>
155+
<buttonGroups>
156+
<group name="shape">
157+
<member id="8a9bd"/>
158+
<member id="e5242"/>
159+
<member id="fdb5a"/>
160+
<member id="6b754"/>
161+
<member id="ab259"/>
162+
</group>
163+
</buttonGroups>
164+
</form>

0 commit comments

Comments
 (0)