diff --git a/src/GUI/ChatScreen.java b/src/GUI/ChatScreen.java index 9449615087d77f8d09f7bf7527073f37aa8248eb..86cc5fb5c09a3c3249b83686d7a504d4a6ba44e2 100644 --- a/src/GUI/ChatScreen.java +++ b/src/GUI/ChatScreen.java @@ -28,4 +28,18 @@ public class ChatScreen { ryanPanel = new PaintGUI().getGlobal(); } + +// public static void main (String[] args) { +// ChatScreen chatScreen = new ChatScreen(); +// chatScreen.go(); +// } + + public void go(){ + //joinButton.addActionListener(actionListener); + frame = new JFrame("App"); + frame.setContentPane(panel2); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.pack(); + frame.setVisible(true); + } } diff --git a/src/GUI/PaintGUI.java b/src/GUI/PaintGUI.java index f63f737bb61ae12d6cd36dd5ec5b50f551e04b3f..74d68ce593ed415444844dbbf67269dc2b951cd1 100644 --- a/src/GUI/PaintGUI.java +++ b/src/GUI/PaintGUI.java @@ -1,5 +1,7 @@ package GUI; +import client.DrawingArea; + import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; diff --git a/src/GUI/StartScreen.java b/src/GUI/StartScreen.java index 8c64799bbb8150d20f6d9e5cf24dd8b362554c28..bb1ec0fe5ef685529ae8f02d632bf93c4d58bbea 100644 --- a/src/GUI/StartScreen.java +++ b/src/GUI/StartScreen.java @@ -22,8 +22,13 @@ public class StartScreen { this.client = client; } + public StartScreen() { + super(); + } + // public static void main(String[] args) { -// new StartScreen().go(); +// StartScreen startScreen = new StartScreen(); +// startScreen.go(); // } @@ -39,7 +44,7 @@ public class StartScreen { if( client.connect() ) { frame.setVisible(false); - frame.dispose(); +// frame.dispose(); client.run(); } else diff --git a/src/client/Client1.java b/src/client/Client1.java deleted file mode 100644 index 18d3b752c54b0006fae74cd71db0722b8018cc0f..0000000000000000000000000000000000000000 --- a/src/client/Client1.java +++ /dev/null @@ -1,73 +0,0 @@ -package client; - -import remote.IChatController; -import remote.IClientController; - -import java.rmi.NotBoundException; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; -import java.util.concurrent.TimeUnit; - -public class Client1 -{ - private String userName; - private Registry registryServer; - private IChatController chatController; - private IClientController clientController; - private ChatUpdate chatUpdate; - - public Client1(String userName) throws RemoteException - { - this.userName = userName; - this.chatUpdate = new ChatUpdate(); - } - - public static void main(String[] args) - { - try - { - Client1 client1 = new Client1("Hai"); - client1.run(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public void run() throws RemoteException, NotBoundException - { - connect(); - - try - { - TimeUnit.MINUTES.sleep(5); - } - catch(Exception e) - { - e.printStackTrace(); - } - } - - public boolean connect() throws RemoteException, NotBoundException - { - registryServer = LocateRegistry.getRegistry("localhost"); - - chatController = (IChatController) registryServer.lookup("ChatController"); - clientController = (IClientController) registryServer.lookup("ClientController"); - - System.out.println(userName + " fetched all controller from RMI registry"); - - if ( clientController.join(userName, this.chatUpdate ) ) - { - System.out.println(userName + " registered at server"); - - return true; - } - - return false; - } - - -} \ No newline at end of file diff --git a/src/client/Client2.java b/src/client/Client2.java deleted file mode 100644 index 3eda56bbcb3ba7adc889775fffdd352da89fe084..0000000000000000000000000000000000000000 --- a/src/client/Client2.java +++ /dev/null @@ -1,76 +0,0 @@ -package client; - -import remote.IChatController; -import remote.IClientController; -import client.ChatUpdate; - -import java.rmi.NotBoundException; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; -import java.util.concurrent.TimeUnit; - -public class Client2 -{ - private String userName; - private Registry registryServer; - private IChatController chatController; - private IClientController clientController; - private ChatUpdate chatUpdate; - - public Client2(String userName) throws RemoteException - { - this.userName = userName; - this.chatUpdate = new ChatUpdate(); - } - - public static void main(String[] args) - { - try - { - Client2 client1 = new Client2("Max"); - client1.run(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public void run() throws RemoteException, NotBoundException - { - connect(); - - chatController.broadcast(userName, "Hello"); - - try - { - TimeUnit.MINUTES.sleep(5); - } - catch(Exception e) - { - e.printStackTrace(); - } - } - - public boolean connect() throws RemoteException, NotBoundException - { - registryServer = LocateRegistry.getRegistry("localhost"); - - chatController = (IChatController) registryServer.lookup("ChatController"); - clientController = (IClientController) registryServer.lookup("ClientController"); - - System.out.println(userName + " fetched all controller from RMI registry"); - - if ( clientController.join(userName, this.chatUpdate ) ) - { - System.out.println(userName + " registered at server"); - - return true; - } - - return false; - } - - -} \ No newline at end of file diff --git a/src/client/PaintGUI.java b/src/client/PaintGUI.java deleted file mode 100644 index 02ea1bce4399175d6903809aea3653751cd2046e..0000000000000000000000000000000000000000 --- a/src/client/PaintGUI.java +++ /dev/null @@ -1,219 +0,0 @@ -package client; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; - -public class PaintGUI { - - - 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"}; - JFrame frame; - JButton clearBtn, newBtn, openBtn, saveBtn, saveAsBtn, closeBtn; - JComboBox colorOptions; - JComboBox shapeOptions; - - DrawingArea drawingArea; - - JFileChooser fileChooser= new JFileChooser(); - JPanel toolbox = new JPanel(); - JPanel fileControl = new JPanel(); - ActionListener actionListener = new ActionListener() { - - public void actionPerformed(ActionEvent e) { - -/// Clear button /// - if (e.getSource() == clearBtn) { - drawingArea.clear(); - -/// Create new canvas /// - } else if (e.getSource() == newBtn) { - int returnVal = JOptionPane.showConfirmDialog(new JFrame(), "Save your current whiteboard?", "Save or Discard", JOptionPane.YES_NO_CANCEL_OPTION); - if (returnVal == JOptionPane.YES_OPTION) { - - drawingArea.saveFile(); - drawingArea.clear(); - - } else if (returnVal == JOptionPane.NO_OPTION) { - - drawingArea.clear(); - - } - -// Open file (PNG only) /// - } else if (e.getSource() == openBtn) { - int returnVal = fileChooser.showOpenDialog(frame); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fileChooser.getSelectedFile(); - drawingArea.openFile(file); - } - -/// Save under project directory without filename (PNG file with default filename) /// - } else if (e.getSource() == saveBtn) { - drawingArea.saveFile(); - -/// Save with other filename (PNG only) /// - } else if (e.getSource() == saveAsBtn) { - fileChooser = new JFileChooser(); - int returnVal = fileChooser.showSaveDialog(frame); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fileChooser.getSelectedFile(); - drawingArea.saveAsFile(file); - } - -/// Close application /// - } else if (e.getSource() == closeBtn) { - System.exit(0); - -/// Choose drawing color /// - } else if (e.getSource() == colorOptions) { - - String colorChosen = (String) colorOptions.getSelectedItem(); - - switch (colorChosen){ - case "Aqua": - drawingArea.setColorAqua(); - break; - case "Black": - drawingArea.setColorBlack(); - break; - case "Blue": - drawingArea.setColorBlue(); - break; - case "Fuchsia": - drawingArea.setColorFuchsia(); - break; - case "Gray": - drawingArea.setColorGray(); - break; - case "Green": - drawingArea.setColorGreen(); - break; - case "Lime": - drawingArea.setColorLime(); - break; - case "Maroon": - drawingArea.setColorMaroon(); - break; - case "Navy": - drawingArea.setColorNavy(); - break; - case "Olive": - drawingArea.setColorOlive(); - break; - case "Purple": - drawingArea.setColorPurple(); - break; - case "Red": - drawingArea.setColorRed(); - break; - case "Silver": - drawingArea.setColorSilver(); - break; - case "Teal": - drawingArea.setColorTeal(); - break; - case "White": - drawingArea.setColorWhite(); - break; - case "Yellow": - drawingArea.setColorYellow(); - break; - } - -/// Choose drawing tool /// - } else if (e.getSource() == shapeOptions) { - - String shapeChosen = (String) shapeOptions.getSelectedItem(); - - switch (shapeChosen){ - case "Freehand": - drawingArea.setModeFreehand(); - break; - case "Line": - drawingArea.setModeLine(); - break; - case "Circle": - drawingArea.setModeCircle(); - break; - case "Rectangle": - drawingArea.setModeRectangle(); - break; - case "Oval": - drawingArea.setModeOval(); - break; - case "Eraser": - drawingArea.setModeErase(); - break; - } - } - } - }; - -/// Main program /// - public static void main(String[] args) { - new PaintGUI().createAndShowGUI(); - } - - -/// GUI setup /// - private void createAndShowGUI() { - -/// Main drawing area /// - drawingArea = new DrawingArea(); - -/// Set up main frame and container /// - frame = new JFrame("Shared Whiteboard System"); - JFrame.setDefaultLookAndFeelDecorated(true); - Container content = frame.getContentPane(); - content.setLayout(new BorderLayout()); - -/// Set up elements /// - shapeOptions = new JComboBox(shapes); - shapeOptions.addActionListener(actionListener); - colorOptions = new JComboBox(colors); - colorOptions.setSelectedItem("Black"); - colorOptions.addActionListener(actionListener); - clearBtn = new JButton("Clear"); - clearBtn.addActionListener(actionListener); - newBtn = new JButton("New"); - newBtn.addActionListener(actionListener); - openBtn = new JButton("Open"); - openBtn.addActionListener(actionListener); - saveBtn = new JButton("Save"); - saveBtn.addActionListener(actionListener); - saveAsBtn = new JButton("Save As"); - saveAsBtn.addActionListener(actionListener); - closeBtn = new JButton("Close"); - closeBtn.addActionListener(actionListener); - -/// Toolbox panel /// - toolbox.add(colorOptions); - toolbox.add(shapeOptions); - toolbox.add(clearBtn); - -/// File control panel /// - fileControl.add(newBtn); - fileControl.add(openBtn); - fileControl.add(saveBtn); - fileControl.add(saveAsBtn); - fileControl.add(closeBtn); - -/// Layout /// - content.add(fileControl, BorderLayout.NORTH); - content.add(drawingArea); - content.add(toolbox, BorderLayout.SOUTH); - -/// Miscellaneous /// - frame.setSize(800, 600); - frame.setLocationRelativeTo( null ); - frame.setResizable(false); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setVisible(true); - - } - -} \ No newline at end of file