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

add ApplicationMain

parent ac8225d5
No related branches found
No related tags found
No related merge requests found
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);
}
}
<?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>
......@@ -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();
// }
}
......@@ -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());
......
......@@ -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;
}
......
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)
{
......
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment