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

Merge branch 'master' of...

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

 Conflicts:
	src/GUI/StartScreen.java
parents 639a2044 eddb94d3
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
</hspacer> </hspacer>
</children> </children>
</grid> </grid>
<grid id="b37e3" binding="x" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="b37e3" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<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"/> <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"/>
...@@ -107,10 +107,10 @@ ...@@ -107,10 +107,10 @@
</component> </component>
</children> </children>
</grid> </grid>
<grid id="be22c" binding="ryanPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="c0bac" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
......
package GUI; package GUI;
import client.Client;
import remote.IChatController;
import remote.IClientController;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
public class ChatScreen { public class ChatScreen {
public JPanel panel2; public JPanel panel2;
private JButton quitButton; private JButton quitButton;
private JButton send; private JButton send;
public JTextArea getChatOutputArea()
{
return chatOutputArea;
}
private JTextArea chatOutputArea; private JTextArea chatOutputArea;
private JTextArea chatInputArea; private JTextArea chatInputArea;
private JTextArea userListArea; private JTextArea userListArea;
...@@ -14,16 +27,65 @@ public class ChatScreen { ...@@ -14,16 +27,65 @@ public class ChatScreen {
private JPanel x; private JPanel x;
private JFrame frame; private JFrame frame;
public ChatScreen(){ private Client client;
public void setChatOutput(String message)
{
this.chatOutputArea.setText(message);
}
ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == send)
{
String message = chatInputArea.getText();
chatInputArea.setText("");
IChatController chatController = client.getChatController();
try
{
System.out.println("Send button pressed");
chatController.broadcastMessage(client.getUserName(), message);
}
catch (RemoteException ex)
{
ex.printStackTrace();
}
}
else if (e.getSource() == quitButton)
{
IClientController clientController = client.getClientController();
try
{
System.out.println("Quit button pressed");
clientController.quit(client.getUserName());
System.exit(0);
}
catch (RemoteException ex)
{
ex.printStackTrace();
}
}
}
};
public ChatScreen(Client client)
{
this.client = client;
quitButton.addActionListener(actionListener);
send.addActionListener(actionListener);
frame = new JFrame("App"); frame = new JFrame("App");
frame.setContentPane(panel2); frame.setContentPane(panel2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack(); frame.pack();
frame.setVisible(true); frame.setVisible(true);
createUIComponents(); createUIComponents();
} }
private void createUIComponents() { private void createUIComponents() {
ryanPanel = new PaintGUI().getGlobal(); ryanPanel = new PaintGUI().getGlobal();
......
...@@ -22,13 +22,8 @@ public class StartScreen { ...@@ -22,13 +22,8 @@ public class StartScreen {
this.client = client; this.client = client;
} }
public StartScreen() {
super();
}
// public static void main(String[] args) { // public static void main(String[] args) {
// StartScreen startScreen = new StartScreen(); // new StartScreen().go();
// startScreen.go();
// } // }
...@@ -44,15 +39,14 @@ public class StartScreen { ...@@ -44,15 +39,14 @@ public class StartScreen {
if( client.connect() ) if( client.connect() )
{ {
frame.setVisible(false); frame.setVisible(false);
// frame.dispose(); frame.dispose();
client.run(); //client.doSomething();
new ChatScreen(client);
} }
else else
{ {
showErrorMessage("Could not connect to server..."); showErrorMessage("Could not connect to server...");
} }
//new ChatScreen();
} }
} }
......
...@@ -8,14 +8,21 @@ import java.rmi.server.UnicastRemoteObject; ...@@ -8,14 +8,21 @@ import java.rmi.server.UnicastRemoteObject;
public class ChatUpdate extends UnicastRemoteObject implements IChatUpdate, Serializable public class ChatUpdate extends UnicastRemoteObject implements IChatUpdate, Serializable
{ {
public ChatUpdate() throws RemoteException private Client client;
public ChatUpdate(Client client) throws RemoteException
{ {
super(); super();
this.client = client;
} }
@Override @Override
public boolean notifyChat(String fromClient, String message) throws RemoteException public boolean notifyChat(String fromClient, String message) throws RemoteException
{ {
// client.getChatScreen().setChatOutput(message);
client.getChatScreen().getChatOutputArea().setText(message);
//client.setReceivedMessage(message);
System.out.println(fromClient + ": " + message); System.out.println(fromClient + ": " + message);
return true; return true;
} }
......
package client; package client;
import GUI.ChatScreen;
import remote.IChatController; import remote.IChatController;
import remote.IClientController; import remote.IClientController;
import client.ChatUpdate; import client.ChatUpdate;
...@@ -25,11 +26,37 @@ public class Client ...@@ -25,11 +26,37 @@ public class Client
private StartScreen startScreen; private StartScreen startScreen;
public ChatScreen getChatScreen()
{
return chatScreen;
}
private ChatScreen chatScreen;
private String receivedMessage;
public IChatController getChatController()
{
return chatController;
}
public IClientController getClientController()
{
return clientController;
}
public void setUsername(String userName) public void setUsername(String userName)
{ {
this.userName = userName; this.userName = userName;
} }
public String getUserName()
{
return this.userName;
}
public void setServerAddress(String serverAddress) public void setServerAddress(String serverAddress)
{ {
this.serverAddress = serverAddress; this.serverAddress = serverAddress;
...@@ -38,7 +65,7 @@ public class Client ...@@ -38,7 +65,7 @@ public class Client
public Client() throws RemoteException public Client() throws RemoteException
{ {
this.userName = "DefaultUser"; this.userName = "DefaultUser";
this.chatUpdate = new ChatUpdate(); this.chatUpdate = new ChatUpdate(this);
this.startScreen = new StartScreen(this); this.startScreen = new StartScreen(this);
this.drawingUpdate = new DrawingUpdate(); this.drawingUpdate = new DrawingUpdate();
} }
...@@ -56,12 +83,13 @@ public class Client ...@@ -56,12 +83,13 @@ public class Client
} }
} }
public void run() public void doSomething()
{ {
//connect(); // new ChatScreen();
try try
{ {
new ChatScreen(this);
System.out.println("Sleeping..."); System.out.println("Sleeping...");
TimeUnit.MINUTES.sleep(5); TimeUnit.MINUTES.sleep(5);
} }
...@@ -95,7 +123,13 @@ public class Client ...@@ -95,7 +123,13 @@ public class Client
return false; return false;
} }
public String getReceivedMessage()
{
return receivedMessage;
}
public void setReceivedMessage(String receivedMessage)
{
this.receivedMessage = receivedMessage;
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment