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

startScreen

parent 7189c58b
No related branches found
No related tags found
No related merge requests found
package GUI;
import javax.swing.*;
public class MenuBar extends JMenuBar {
JButton clearBtn, newBtn, openBtn, saveBtn, saveAsBtn, closeBtn;
}
......@@ -11,10 +11,12 @@
<grid id="abaca" layout-manager="GridLayoutManager" row-count="3" 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="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="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="100" height="70"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<border type="none" title=" "/>
<children>
<hspacer id="53fe0">
<constraints>
......@@ -23,52 +25,37 @@
</hspacer>
<component id="ebca9" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Apple SD Gothic Neo" size="20"/>
<text value="Distributed Whiteboard App"/>
</properties>
</component>
<component id="d60e2" class="javax.swing.JTextArea" binding="information">
<component id="e3c91" class="javax.swing.JTextPane" binding="information">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
<preferred-size width="150" height="70"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
<text value="Welcome, please provide server's IP to connect to and nameto be identified by in the Whiteboard's chat."/>
<text value="Welcome to Distributed Whiteboard. Please provide server's IP, username, and password."/>
</properties>
</component>
</children>
</grid>
<grid id="790e1" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="790e1" 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="2" 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="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="87b91" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Your name:"/>
</properties>
</component>
<component id="e39f4" class="javax.swing.JTextField" binding="textField1" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="ea0c1" class="javax.swing.JButton" binding="joinButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="JOIN WHITEBOARD"/>
......@@ -76,22 +63,20 @@
</component>
</children>
</grid>
<grid id="6ef31" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="6ef31" 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"/>
<constraints>
<grid row="1" 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="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<properties>
<name value=""/>
<requestFocusEnabled value="false"/>
</properties>
<border type="none" title=" "/>
<children>
<hspacer id="23c9f">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="94078" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Server IP:"/>
......@@ -99,7 +84,7 @@
</component>
<component id="63209" class="javax.swing.JTextField" binding="textField2">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
......@@ -107,6 +92,45 @@
<text value=""/>
</properties>
</component>
<vspacer id="bb71b">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="87b91" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Your name:"/>
</properties>
</component>
<component id="e39f4" class="javax.swing.JTextField" binding="textField1" default-binding="true">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="51d9f" class="javax.swing.JPasswordField" binding="passwordField">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<columns value="20"/>
</properties>
</component>
<component id="62e48" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Password:"/>
</properties>
</component>
</children>
</grid>
</children>
......
......@@ -8,11 +8,13 @@ import java.awt.event.ActionListener;
public class StartScreen {
private JTextPane information;
private JPanel panel1;
private JTextArea information;
private JTextField textField1;
private JButton joinButton;
private JTextField textField2;
private JTextField textField3;
private JPasswordField passwordField;
JFrame frame;
private Client client;
......@@ -35,8 +37,9 @@ public class StartScreen {
{
String serverAddress = textField2.getText();
String userName = textField1.getText();
String password = new String(passwordField.getPassword());
int connectionStatus = client.connect(userName, serverAddress);
int connectionStatus = client.connect(userName, serverAddress, password);
if( connectionStatus == 1 )
{
......@@ -52,6 +55,10 @@ public class StartScreen {
{
showErrorMessage("Cannot connect to server: Please check the server address");
}
else if( connectionStatus == 4 )
{
showErrorMessage("Incorrect Password");
}
else
{
showErrorMessage("Unknown Connection Status");
......@@ -74,7 +81,9 @@ public class StartScreen {
frame.setContentPane(panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.getRootPane().setDefaultButton(joinButton);
joinButton.requestFocus();
frame.setVisible(true);
}
}
package GUI;
import javax.swing.*;
import java.awt.*;
public class ToolBar extends JPanel {
private DrawingArea drawingArea;
public ToolBar() {
}
}
class Tools extends JPanel {
}
class ColorPallete extends JPanel {
private Color color;
public ColorPallete() {
this.color = new Color(0, 0, 0); // Black
}
public void setColor(Color color) {
this.color = color;
}
public void setColorRBG(int r, int b, int g) {
this.color = new Color(r, b, g);
}
public Color getColor() {
return this.color;
}
public void setColorAqua() {
this.color = new Color(0,255, 255);
}
public void setColorBlack() {
this.color = new Color(0, 0, 0);
}
public void setColorBlue() {
this.color = new Color(0, 0, 255);
}
public void setColorFuchsia() {
this.color = new Color(255, 0, 255);
}
public void setColorGray() {
this.color = new Color(128, 128, 128);
}
public void setColorGreen() {
this.color = new Color(0, 128, 0);
}
public void setColorLime() {
this.color = new Color(0, 255, 0);
}
public void setColorMaroon() {
this.color = new Color(128,0, 0);
}
public void setColorNavy() {
this.color = new Color(0, 0, 128);
}
public void setColorOlive() {
this.color = new Color(128, 128, 0);
}
public void setColorPurple() {
this.color = new Color(128, 0, 128);
}
public void setColorRed() {
this.color = new Color(255, 0, 0);
}
public void setColorSilver() {
this.color = new Color(192, 192, 192);
}
public void setColorTeal() {
this.color = new Color(0, 128, 128);
}
public void setColorWhite() {
this.color = new Color(255, 255, 255);
}
public void setColorYellow() {
this.color = new Color(255, 255, 0);
}
}
\ No newline at end of file
......@@ -28,9 +28,8 @@ public class Client
private ClientUpdate clientUpdate;
private ChatUpdate chatUpdate;
private DrawingUpdate drawingUpdate;
private ApplicationMain applicationMain;
private StartScreen startScreen;
private PaintGUI paintGUI;
public String getUserName()
......@@ -53,13 +52,9 @@ public class Client
this.serverAddress = serverAddress;
}
private ApplicationMain applicationMain;
public ApplicationMain getApplicationMain() { return applicationMain; }
public PaintGUI getPaintGUI() {
return paintGUI;
}
public ApplicationMain getApplicationMain() { return applicationMain; }
public ChatScreen getChatScreen() {
return getApplicationMain().getChatScreen();
......@@ -98,6 +93,7 @@ public class Client
catch (Exception e)
{
StartScreen.showErrorMessage("Error starting up client");
System.exit(0);
}
}
......@@ -117,7 +113,8 @@ public class Client
// return = 1 -> connected successfully
// return = 2 -> duplicate username
// return = 3 -> error in locating the server
public int connect(String userName, String serverAddress)
// return = 4 -> incorrect password entered
public int connect(String userName, String serverAddress, String password)
{
if( !userName.trim().isEmpty() )
{
......@@ -142,6 +139,10 @@ public class Client
drawingController = (IDrawingController) registryServer.lookup("DrawingController");
System.out.println("User name: " + userName);
System.out.println("Password: " + password);
if( clientController.checkPassword(password) )
{
if( clientController.join(userName, this.chatUpdate, this.clientUpdate, this.drawingUpdate) )
{
System.out.println("Connected to server");
......@@ -153,12 +154,15 @@ public class Client
return 2;
}
}
else
{
return 4;
}
}
catch (Exception e)
{
//e.printStackTrace();
return 3;
}
}
}
\ No newline at end of file
......@@ -41,18 +41,14 @@ public class ClientUpdate extends UnicastRemoteObject implements IClientUpdate,
{
printUserList(users);
System.out.println("TEST1");
JComboBox userBox = client.getApplicationMain().getChatScreen().getSendMessageToComboBox();
JComboBox kickUserBox = client.getChatScreen().getKickUserComboBox();
System.out.println("TEST2");
userBox.removeAllItems();
kickUserBox.removeAllItems();
System.out.println("TEST3");
userBox.addItem("All");
System.out.println("TEST4");
for( String s : users )
{
if( !s.equals(client.getUserName()) )
......
......@@ -18,4 +18,6 @@ public interface IClientController extends Remote
boolean broadcastManagerMessage(String toClient, Action action) throws RemoteException;
String getAdmin() throws RemoteException;
boolean checkPassword(String password) throws RemoteException;
}
......@@ -62,7 +62,7 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
broadcastUserList();
}
printUserList();
//printUserList();
}
// for debuggins purposes
......@@ -71,7 +71,7 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
System.out.print("Currently connected users: ");
for( User u : server.users )
{
System.out.print(u.getUserName());
System.out.print(u.getUserName() + " ");
}
System.out.println();
}
......@@ -105,10 +105,12 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
if ( adminIndex >= 0 && userIndex >= 0 && server.users.get(adminIndex).isAdmin() )
{
try {
try
{
server.users.get(userIndex).getIClientUpdate().terminateChat();
}
finally {
finally
{
System.out.print(server.users);
server.users.remove(userIndex);
System.out.print(server.users);
......@@ -202,4 +204,23 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
return true;
}
@Override
public boolean checkPassword(String password)
{
if( server.users.size() == 0 )
{
server.setPassword(password);
return true;
}
else if( server.getPassword().equals(password) )
{
return true;
}
else
{
return false;
}
}
}
......@@ -17,14 +17,27 @@ public class Server
protected ChatController chatController;
protected DrawingController drawingController;
private String password;
public Server() throws RemoteException
{
password = null;
users = new ArrayList<User>();
clientController = new ClientController(this);
chatController = new ChatController(this);
drawingController = new DrawingController(this);
}
protected void setPassword(String password)
{
this.password = password;
}
protected String getPassword()
{
return password;
}
public static void main(String[] args)
{
try
......@@ -49,17 +62,13 @@ public class Server
String chatControllerName = "ChatController";
String drawingControllerName = "DrawingController";
// IClientController clientController = new ClientController(this);
// IChatController chatController = new ChatController(this);
// IDrawingController drawingController = new DrawingController(this);
IClientController iclientController = this.clientController;
IChatController ichatController = this.chatController;
IDrawingController idrawingController = this.drawingController;
IClientController clientController = this.clientController;
IChatController chatController = this.chatController;
IDrawingController drawingController = this.drawingController;
registry.rebind(clientControllerName, iclientController);
registry.rebind(chatControllerName, ichatController);
registry.rebind(drawingControllerName, idrawingController);
registry.rebind(clientControllerName, clientController);
registry.rebind(chatControllerName, chatController);
registry.rebind(drawingControllerName, drawingController);
System.out.println("Server is ready");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment