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

commit

parent 033d77a7
Branches
Tags
No related merge requests found
...@@ -33,28 +33,23 @@ public class ChatScreen { ...@@ -33,28 +33,23 @@ public class ChatScreen {
private JButton quitButton; private JButton quitButton;
private JFrame frame; private JFrame frame;
private Client client; public Client getClient() {
return client;
}
public Client client;
public ChatScreen(Client client) public ChatScreen(Client client)
{ {
this.client = client; this.client = client;
yourNameDisplay.setText(client.getUserName()); exitThisRoomButton.addActionListener(actionListener);
// sentMessageToComboBox.addItem(client.getUserName());
quitButton.addActionListener(actionListener);
sendButton.addActionListener(actionListener); sendButton.addActionListener(actionListener);
frame = new JFrame("Application"); yourNameDisplay.setText(client.getUserName());
frame.setContentPane(panel2); drawingPanel = new PaintGUI(client);
createUIComponents();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
} }
private void createUIComponents() {
drawingPanel = new PaintGUI(client).getGlobal();
}
public JTextArea getChatDisplayBox() { public JTextArea getChatDisplayBox() {
return chatDisplayBox; return chatDisplayBox;
...@@ -104,4 +99,20 @@ public class ChatScreen { ...@@ -104,4 +99,20 @@ public class ChatScreen {
} }
}; };
public void showGUI() {
frame = new JFrame("Application");
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setContentPane(panel2);
createUIComponents();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
}
private void createUIComponents() {
// PaintGUI paintGUI = new PaintGUI(client);
drawingPanel = new PaintGUI(client).getGlobal();
}
} }
...@@ -10,7 +10,8 @@ import java.io.File; ...@@ -10,7 +10,8 @@ import java.io.File;
public class PaintGUI extends JPanel { public class PaintGUI extends JPanel {
Client client;
ChatScreen chatScreen;
String[] shapes = {"Freehand", "Line", "Circle", "Rectangle", "Oval", "Eraser"}; String[] shapes = {"Freehand", "Line", "Circle", "Rectangle", "Oval", "Eraser"};
String[] colors = {"Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green", "Lime", "Maroon", "Navy", "Olive", "Purple", "Red", "Silver", "Teal", "White", "Yellow"}; String[] colors = {"Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green", "Lime", "Maroon", "Navy", "Olive", "Purple", "Red", "Silver", "Teal", "White", "Yellow"};
...@@ -19,7 +20,8 @@ public class PaintGUI extends JPanel { ...@@ -19,7 +20,8 @@ public class PaintGUI extends JPanel {
JComboBox colorOptions; JComboBox colorOptions;
JComboBox shapeOptions; JComboBox shapeOptions;
DrawingArea drawingArea; DrawingArea drawingArea;
Client client;
JPanel global = new JPanel(); JPanel global = new JPanel();
JFileChooser fileChooser= new JFileChooser(); JFileChooser fileChooser= new JFileChooser();
JPanel toolbox = new JPanel(); JPanel toolbox = new JPanel();
...@@ -27,10 +29,11 @@ public class PaintGUI extends JPanel { ...@@ -27,10 +29,11 @@ public class PaintGUI extends JPanel {
/// GUI setup /// /// GUI setup ///
public PaintGUI(Client client) { public PaintGUI(Client client) {
this.client = client; this.client = client;
/// Main drawing area /// /// Main drawing area ///
drawingArea = new DrawingArea(client); drawingArea = new DrawingArea(this.client);
/// Set up main frame and container /// /// Set up main frame and container ///
global.setLayout(new BorderLayout()); global.setLayout(new BorderLayout());
...@@ -215,16 +218,16 @@ public class PaintGUI extends JPanel { ...@@ -215,16 +218,16 @@ public class PaintGUI extends JPanel {
// public void showGUI() { public void showGUI() {
// frame = new JFrame("Shared Whiteboard System"); frame = new JFrame("Shared Whiteboard System");
// JFrame.setDefaultLookAndFeelDecorated(true); JFrame.setDefaultLookAndFeelDecorated(true);
// frame.setContentPane(global); frame.setContentPane(global);
//
// frame.setSize(800, 600); frame.setSize(800, 600);
// frame.setLocationRelativeTo( null ); frame.setLocationRelativeTo( null );
// frame.setResizable(false); frame.setResizable(false);
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.setVisible(true); frame.setVisible(true);
// } }
} }
\ No newline at end of file
...@@ -13,7 +13,6 @@ import java.rmi.registry.Registry; ...@@ -13,7 +13,6 @@ import java.rmi.registry.Registry;
public class Client public class Client
{ {
//test
private String userName; private String userName;
private String serverAddress; private String serverAddress;
...@@ -28,11 +27,11 @@ public class Client ...@@ -28,11 +27,11 @@ public class Client
private StartScreen startScreen; private StartScreen startScreen;
private ChatScreen chatScreen; private ChatScreen chatScreen;
// private PaintGUI paintGUI; private PaintGUI paintGUI;
// public PaintGUI getPaintGUI() { public PaintGUI getPaintGUI() {
// return paintGUI; return paintGUI;
// } }
public ChatScreen getChatScreen() public ChatScreen getChatScreen()
...@@ -40,10 +39,6 @@ public class Client ...@@ -40,10 +39,6 @@ public class Client
return chatScreen; return chatScreen;
} }
private String receivedMessage;
public IChatController getChatController() public IChatController getChatController()
{ {
return chatController; return chatController;
...@@ -77,7 +72,7 @@ public class Client ...@@ -77,7 +72,7 @@ public class Client
this.clientUpdate = new ClientUpdate(this); this.clientUpdate = new ClientUpdate(this);
this.chatUpdate = new ChatUpdate(this); this.chatUpdate = new ChatUpdate(this);
this.drawingUpdate = new DrawingUpdate(this); this.drawingUpdate = new DrawingUpdate(this);
this.startScreen = new StartScreen(this); // this.startScreen = new StartScreen(this);
this.chatScreen = new ChatScreen(this); this.chatScreen = new ChatScreen(this);
// this.paintGUI = new PaintGUI(this); // this.paintGUI = new PaintGUI(this);
} }
...@@ -88,7 +83,7 @@ public class Client ...@@ -88,7 +83,7 @@ public class Client
{ {
Client client = new Client(args[0]); Client client = new Client(args[0]);
client.connect(); client.connect();
// client.startScreen.go(); client.chatScreen.showGUI();
// client.getPaintGUI().showGUI(); // client.getPaintGUI().showGUI();
} }
catch (Exception e) catch (Exception e)
...@@ -107,7 +102,7 @@ public class Client ...@@ -107,7 +102,7 @@ public class Client
clientController = (IClientController) registryServer.lookup("ClientController"); clientController = (IClientController) registryServer.lookup("ClientController");
drawingController = (IDrawingController) registryServer.lookup("DrawingController"); drawingController = (IDrawingController) registryServer.lookup("DrawingController");
if (clientController.join(userName, this.chatUpdate, this.drawingUpdate)) if (clientController.join(userName, this.chatUpdate, this.drawingUpdate, this.clientUpdate))
{ {
System.out.println("Connected to server"); System.out.println("Connected to server");
......
package client; package client;
import GUI.DrawingArea;
import remote.IDrawingUpdate; import remote.IDrawingUpdate;
import java.awt.*; import java.awt.*;
...@@ -18,9 +19,11 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate ...@@ -18,9 +19,11 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate
@Override @Override
public boolean notifyDrawing(String fromClient, Shape drawing) throws RemoteException { public boolean notifyDrawing(String fromClient, Shape drawing) throws RemoteException {
// client.getPaintGUI().getDrawingArea().setDrawing(drawing); client.getPaintGUI().getDrawingArea().setDrawing(drawing);
// client.getPaintGUI().getDrawingArea().repaint(); client.getPaintGUI().getDrawingArea().repaint();
client.getChatScreen().getDrawingPanel().getRootPane(); DrawingArea drawingArea = (DrawingArea) client.getChatScreen().getDrawingPanel().getComponent(1);
drawingArea.setDrawing(drawing);
drawingArea.repaint();
return false; return false;
} }
} }
...@@ -5,7 +5,7 @@ import java.rmi.RemoteException; ...@@ -5,7 +5,7 @@ import java.rmi.RemoteException;
public interface IClientController extends Remote public interface IClientController extends Remote
{ {
boolean join(String username, IChatUpdate clientChat, IDrawingUpdate clientDrawing) throws RemoteException; boolean join(String username, IChatUpdate clientChat, IDrawingUpdate clientDrawing, IClientUpdate clientUpdate) throws RemoteException;
void quit(String username) throws RemoteException; void quit(String username) throws RemoteException;
......
package remote;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.ArrayList;
/**
* RMI Remote interface - IRemoteUpdate.
* Allows Server to command Client to update: canvas, chat, other.
*/
public interface IUpdateController extends Remote {
public void updateClient(String text) throws RemoteException;
public ArrayList<String> getUserList() throws RemoteException;
public void updateUserList(ArrayList userList) throws RemoteException;
}
package server; package server;
import remote.IChatUpdate; import remote.IChatUpdate;
import remote.IClientController; import remote.IClientUpdate;
import remote.IDrawingUpdate; import remote.IDrawingUpdate;
import remote.IClientController;
import java.io.Serializable; import java.io.Serializable;
import java.rmi.RemoteException; import java.rmi.RemoteException;
...@@ -18,11 +19,11 @@ public class ClientController extends UnicastRemoteObject implements IClientCont ...@@ -18,11 +19,11 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
} }
@Override @Override
public boolean join(String username, IChatUpdate clientChat, IDrawingUpdate clientDrawing) throws RemoteException public boolean join(String username, IChatUpdate clientChat, IDrawingUpdate clientDrawing, IClientUpdate clientUpdate) throws RemoteException
{ {
server.chatController.broadcastMessageUserLogin(username); server.chatController.broadcastMessageUserLogin(username);
User newUser = new User(username, clientChat, clientDrawing); User newUser = new User(username, clientChat, clientDrawing, clientUpdate);
server.users.add(newUser); server.users.add(newUser);
......
...@@ -15,12 +15,14 @@ public class Server ...@@ -15,12 +15,14 @@ public class Server
protected ClientController clientController; protected ClientController clientController;
protected ChatController chatController; protected ChatController chatController;
protected DrawingController drawingController;
public Server() throws RemoteException public Server() throws RemoteException
{ {
users = new ArrayList<User>(); users = new ArrayList<User>();
clientController = new ClientController(this); clientController = new ClientController(this);
chatController = new ChatController(this); chatController = new ChatController(this);
drawingController = new DrawingController(this);
} }
public static void main(String[] args) public static void main(String[] args)
......
package server; package server;
import remote.IChatUpdate;
import remote.IClientUpdate;
import remote.IDrawingUpdate;
public class User public class User
{ {
private String username; private String username;
private remote.IChatUpdate IChatUpdate; private IChatUpdate IChatUpdate;
private remote.IDrawingUpdate IDrawingUpdate; private IDrawingUpdate IDrawingUpdate;
private IClientUpdate IClientUpdate;
private boolean isAdmin; private boolean isAdmin;
public User(String username, remote.IChatUpdate IChatUpdate, remote.IDrawingUpdate IDrawingUpdate) public User(String username, IChatUpdate IChatUpdate, IDrawingUpdate IDrawingUpdate, IClientUpdate IClientUpdate)
{ {
this.username = username; this.username = username;
this.IChatUpdate = IChatUpdate; this.IChatUpdate = IChatUpdate;
this.IDrawingUpdate = IDrawingUpdate; this.IDrawingUpdate = IDrawingUpdate;
this.IClientUpdate = IClientUpdate;
this.isAdmin = false; this.isAdmin = false;
} }
...@@ -30,10 +36,12 @@ public class User ...@@ -30,10 +36,12 @@ public class User
return isAdmin; return isAdmin;
} }
public remote.IChatUpdate getIChatUpdate() public IChatUpdate getIChatUpdate()
{ {
return this.IChatUpdate; return this.IChatUpdate;
} }
public remote.IDrawingUpdate getIDrawingUpdate() { return this.IDrawingUpdate; } public IDrawingUpdate getIDrawingUpdate() { return this.IDrawingUpdate; }
public IClientUpdate getIClientUpdate() { return this.IClientUpdate; }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment