diff --git a/src/GUI/ApplicationMain.java b/src/GUI/ApplicationMain.java new file mode 100644 index 0000000000000000000000000000000000000000..35fa142780124d59425104ad2c172435b787f8d5 --- /dev/null +++ b/src/GUI/ApplicationMain.java @@ -0,0 +1,44 @@ +package GUI; + +import client.Client; + +import javax.swing.*; +import java.awt.*; + +public class ApplicationMain extends JPanel { + Client client; + ChatScreen chatScreen; + PaintGUI paintGUI; + JFrame frame; + + public ChatScreen getChatScreen() { return chatScreen; } + + public PaintGUI getPaintGUI() { return paintGUI; } + + public JFrame getFrame() { + return frame; + } + + public ApplicationMain(Client client) { + this.client = client; + this.chatScreen = new ChatScreen(client); + this.paintGUI = new PaintGUI(client); + } + + public void createAndShowGUI() { + frame = new JFrame("Application Main"); + JFrame.setDefaultLookAndFeelDecorated(true); + Container content = frame.getContentPane(); + content.setLayout(new BorderLayout()); + content.add(paintGUI.getGlobal(), BorderLayout.WEST); + content.add(chatScreen.panel2, BorderLayout.EAST); + + frame.setSize(1200, 700); + frame.setLocationRelativeTo( null ); + frame.setResizable(false); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.pack(); + frame.setVisible(true); + } + +} diff --git a/src/GUI/ChatScreen.form b/src/GUI/ChatScreen.form index 7ff8dffbe24b88abe437e256e76198ea323b9a90..dcf86520dca8b4420e5c4f567db759d88b36fac5 100644 --- a/src/GUI/ChatScreen.form +++ b/src/GUI/ChatScreen.form @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="GUI.ChatScreen"> - <grid id="27dc6" binding="panel2" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="27dc6" binding="panel2" 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"/> <constraints> <xy x="20" y="20" width="1200" height="1200"/> @@ -8,14 +8,14 @@ <properties> <maximumSize width="-1" height="-1"/> <minimumSize width="-1" height="-1"/> - <preferredSize width="1200" height="700"/> + <preferredSize width="700" height="700"/> </properties> <border type="none"/> <children> <grid id="b37e3" binding="othersPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <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="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/> </constraints> <properties/> <border type="none"/> @@ -195,15 +195,6 @@ </grid> </children> </grid> - <grid id="be22c" binding="drawingPanel" custom-create="true" 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"/> - <constraints> - <grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/> - </constraints> - <properties/> - <border type="none" title="Drawing Area"/> - <children/> - </grid> </children> </grid> </form> diff --git a/src/GUI/ChatScreen.java b/src/GUI/ChatScreen.java index 0c43cd56aa801ee4e5c3f6b6c891e93f1c4a53cd..5e34602532912e5931c1201fd5bc0276e3d8ce95 100644 --- a/src/GUI/ChatScreen.java +++ b/src/GUI/ChatScreen.java @@ -13,7 +13,7 @@ public class ChatScreen { public JPanel panel2; private JButton sendButton; - private JPanel drawingPanel; +// private JPanel drawingPanel; private JPanel othersPanel; private JComboBox sentMessageToComboBox; private JTextArea chatDisplayBox; @@ -46,7 +46,7 @@ public class ChatScreen { exitThisRoomButton.addActionListener(actionListener); sendButton.addActionListener(actionListener); yourNameDisplay.setText(client.getUserName()); - drawingPanel = new PaintGUI(client); +// drawingPanel = new PaintGUI(client); } @@ -59,9 +59,9 @@ public class ChatScreen { return sentMessageToComboBox; } - public JPanel getDrawingPanel() { - return drawingPanel; - } +// public JPanel getDrawingPanel() { +// return drawingPanel; +// } ActionListener actionListener = new ActionListener() { @@ -104,15 +104,15 @@ public class ChatScreen { frame = new JFrame("Application"); JFrame.setDefaultLookAndFeelDecorated(true); frame.setContentPane(panel2); - createUIComponents(); +// createUIComponents(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setResizable(false); frame.setVisible(true); } - private void createUIComponents() { +// private void createUIComponents() { // PaintGUI paintGUI = new PaintGUI(client); - drawingPanel = new PaintGUI(client).getGlobal(); - } +// drawingPanel = paintGUI.getGlobal(); +// } } diff --git a/src/GUI/PaintGUI.java b/src/GUI/PaintGUI.java index 2995d3be8c34304669416ed3df79c001f413c4e8..40a63589b23c67847eade7ad28d6ae306516d3fd 100644 --- a/src/GUI/PaintGUI.java +++ b/src/GUI/PaintGUI.java @@ -11,7 +11,6 @@ import java.io.File; public class PaintGUI extends JPanel { Client client; - ChatScreen chatScreen; 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"}; @@ -33,7 +32,7 @@ public class PaintGUI extends JPanel { this.client = client; /// Main drawing area /// - drawingArea = new DrawingArea(this.client); + drawingArea = new DrawingArea(client); /// Set up main frame and container /// global.setLayout(new BorderLayout()); diff --git a/src/client/ChatUpdate.java b/src/client/ChatUpdate.java index 986f6a70224f04c9516b4c0813cd90305cf79f4b..08f89e0250c96e7fd0dfb8784948650a0ef536b7 100644 --- a/src/client/ChatUpdate.java +++ b/src/client/ChatUpdate.java @@ -19,7 +19,7 @@ public class ChatUpdate extends UnicastRemoteObject implements IChatUpdate, Seri @Override public boolean notifyChat(String fromClient, String message) throws RemoteException { - client.getChatScreen().getChatDisplayBox().append(fromClient + ": " + message + "\n"); + client.getApplicationMain().getChatScreen().getChatDisplayBox().append(fromClient + ": " + message + "\n"); //client.setReceivedMessage(message); System.out.println(fromClient + ": " + message); @@ -28,13 +28,13 @@ public class ChatUpdate extends UnicastRemoteObject implements IChatUpdate, Seri @Override public boolean notifyUserLogin(String fromClient) throws RemoteException { - client.getChatScreen().getChatDisplayBox().append(fromClient + " has joined the room.\n"); + client.getApplicationMain().getChatScreen().getChatDisplayBox().append(fromClient + " has joined the room.\n"); return true; } @Override public boolean notifyUserLogout(String fromClient) throws RemoteException { - client.getChatScreen().getChatDisplayBox().append(fromClient + " has left the room.\n"); + client.getApplicationMain().getChatScreen().getChatDisplayBox().append(fromClient + " has left the room.\n"); return true; } diff --git a/src/client/Client.java b/src/client/Client.java index ef1939cbdd44061af06cfc932cf65f3a89b26ce2..01b31948b538c3234abf87aafbe8ccf80126720f 100644 --- a/src/client/Client.java +++ b/src/client/Client.java @@ -1,5 +1,6 @@ package client; +import GUI.ApplicationMain; import GUI.ChatScreen; import GUI.PaintGUI; import GUI.StartScreen; @@ -29,15 +30,14 @@ public class Client private ChatScreen chatScreen; private PaintGUI paintGUI; - public PaintGUI getPaintGUI() { - return paintGUI; - } + public ApplicationMain getApplicationMain() { return applicationMain; } + private ApplicationMain applicationMain; - public ChatScreen getChatScreen() - { - return chatScreen; - } + public PaintGUI getPaintGUI() { return paintGUI; } + + + public ChatScreen getChatScreen() { return chatScreen; } public IChatController getChatController() { @@ -73,8 +73,10 @@ public class Client this.chatUpdate = new ChatUpdate(this); this.drawingUpdate = new DrawingUpdate(this); // this.startScreen = new StartScreen(this); - this.chatScreen = new ChatScreen(this); +// this.chatScreen = new ChatScreen(this); // this.paintGUI = new PaintGUI(this); + this.applicationMain = new ApplicationMain(this); + } public static void main(String[] args) @@ -83,8 +85,9 @@ public class Client { Client client = new Client(args[0]); client.connect(); - client.chatScreen.showGUI(); +// client.getChatScreen().showGUI(); // client.getPaintGUI().showGUI(); + client.getApplicationMain().createAndShowGUI(); } catch (Exception e) { diff --git a/src/client/DrawingUpdate.java b/src/client/DrawingUpdate.java index d681f1aa85f9a116686ea320a10371c6f7d884b9..4b41c0285681b1674f9b35cc61336ca6d4451426 100644 --- a/src/client/DrawingUpdate.java +++ b/src/client/DrawingUpdate.java @@ -19,11 +19,11 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate @Override public boolean notifyDrawing(String fromClient, Shape drawing) throws RemoteException { - client.getPaintGUI().getDrawingArea().setDrawing(drawing); - client.getPaintGUI().getDrawingArea().repaint(); - DrawingArea drawingArea = (DrawingArea) client.getChatScreen().getDrawingPanel().getComponent(1); - drawingArea.setDrawing(drawing); - drawingArea.repaint(); + client.getApplicationMain().getPaintGUI().getDrawingArea().setDrawing(drawing); + client.getApplicationMain().getPaintGUI().getDrawingArea().repaint(); +// DrawingArea drawingArea = (DrawingArea) client.getChatScreen().getDrawingPanel().getComponent(1); +// drawingArea.setDrawing(drawing); +// drawingArea.repaint(); return false; } }