Skip to content
Snippets Groups Projects
Commit afa837e5 authored by Hai HoDac's avatar Hai HoDac
Browse files

Merge branch 'mpriymak' of...

Merge branch 'mpriymak' of https://gitlab.eng.unimelb.edu.au/1050369/comp90015-dsass2-infinitymonkeys-remaster into hai

 Conflicts:
	src/GUI/StartScreen.java
	src/client/Client.java
	src/server/ChatController.java
parents eb852092 17c59007
Branches
Tags
No related merge requests found
......@@ -97,13 +97,15 @@
<text value="Server IP:"/>
</properties>
</component>
<component id="63209" class="javax.swing.JTextField" binding="textField2" default-binding="true">
<component id="63209" class="javax.swing.JTextField" binding="textField2">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
......
package GUI;
import client.Client;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
......@@ -13,20 +15,53 @@ public class StartScreen {
private JTextField textField2;
JFrame frame;
private Client client;
public StartScreen(Client client)
{
this.client = client;
}
// public static void main(String[] args) {
// new StartScreen().go();
// }
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == joinButton) {
if (e.getSource() == joinButton)
{
client.setUsername(textField1.getText());
client.setServerAddress(textField2.getText());
if( client.connect() )
{
frame.setVisible(false);
frame.dispose();
new ChatScreen();
}
else
{
showErrorMessage("Could not connect to server...");
}
client.
//new ChatScreen();
}
}
};
private void showErrorMessage(String message)
{
JOptionPane.showMessageDialog(null,
message, "Error", JOptionPane.PLAIN_MESSAGE);
}
public StartScreen(){
public void go(){
joinButton.addActionListener(actionListener);
frame = new JFrame("App");
frame.setContentPane(panel1);
......
......@@ -4,6 +4,7 @@ import remote.IChatController;
import remote.IClientController;
import client.ChatUpdate;
import client.DrawingUpdate;
import GUI.StartScreen;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
......@@ -14,15 +15,29 @@ import java.util.concurrent.TimeUnit;
public class Client
{
private String userName;
private String serverAddress;
private Registry registryServer;
private IChatController chatController;
private IClientController clientController;
private ChatUpdate chatUpdate;
private DrawingUpdate drawingUpdate;
public Client(String userName) throws RemoteException
private StartScreen startScreen;
public void setUsername(String userName)
{
this.userName = userName;
}
public void setServerAddress(String serverAddress)
{
this.serverAddress = serverAddress;
}
public Client() throws RemoteException
{
this.userName = "DefaultUser";
this.chatUpdate = new ChatUpdate();
this.drawingUpdate = new DrawingUpdate();
}
......@@ -31,8 +46,8 @@ public class Client
{
try
{
Client client1 = new Client("Max");
client1.run();
Client client = new Client();
client.startScreen.go();
}
catch (Exception e)
{
......@@ -65,7 +80,7 @@ public class Client
if ( clientController.join(userName, this.chatUpdate, this.drawingUpdate ) )
{
System.out.println(userName + " registered at server");
System.out.println("Connected to server");
return true;
}
......
......@@ -41,6 +41,8 @@ public class Client2
{
connect();
chatController.broadcast(userName, "Hello");
try
{
TimeUnit.MINUTES.sleep(5);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment