Commit fa645660 authored by Ali Saeed's avatar Ali Saeed

Upload chat app

parents
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="ChatClient" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="7b8eead6-3c0f-4198-a97c-e7ea933bffc2" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/ChatClientService.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Interface" />
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2XqPu0GtqirbYBJwRdLT740kXaB" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH&quot;: &quot;193&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/dell/IdeaProjects/ChatClient/src/Images&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;
},
&quot;keyToStringList&quot;: {
&quot;com.intellij.ide.scratch.ScratchImplUtil$2/New Scratch File&quot;: [
&quot;PLAIN_TEXT&quot;
]
}
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\dell\IdeaProjects\ChatClient\src\Images" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\dell\IdeaProjects\ChatClient\src\main\java\Images" />
<recent name="C:\Users\dell\IdeaProjects\ChatClient\src" />
<recent name="C:\Users\dell\IdeaProjects\ChatClient\src\main\java\org\example" />
<recent name="C:\Users\dell\IdeaProjects\ChatClient\src\main\java" />
<recent name="C:\Users\dell\IdeaProjects\ChatClient\src\main\Images" />
</key>
</component>
<component name="RunManager" selected="Application.ChatClientService">
<configuration name="ChatClientService" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.ChatClientService" />
<module name="ChatClient" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="org.example.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="LoginForm" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.LoginForm" />
<module name="ChatClient" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="org.example.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="RegistrationForm" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.RegistrationForm" />
<module name="ChatClient" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.ChatClientService" />
<item itemvalue="Application.LoginForm" />
<item itemvalue="Application.RegistrationForm" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="7b8eead6-3c0f-4198-a97c-e7ea933bffc2" name="Changes" comment="" />
<created>1699353857888</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1699353857888</updated>
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<breakpoint enabled="true" type="java-exception">
<properties class="java.lang.NullPointerException" package="java.lang" />
<option name="timeStamp" value="1" />
</breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ChatClient</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
package Data;
public class Message {
}
package Data;
import java.io.Serializable;
public class Result implements Serializable {
private boolean isSuccess;
private String description;
public Result(boolean isSuccess, String description) {
this.isSuccess = isSuccess;
this.description = description;
}
public Result() {
this.description="";
this.isSuccess = false;
}
public void setSuccess(boolean success) {
isSuccess = success;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isSuccess() {
return isSuccess;
}
public String getDescription() {
return description;
}
}
package Data;
import javax.jws.soap.SOAPBinding;
import java.util.ArrayList;
import java.util.List;
public class Room {
private String roomName;
private List<User> users;
private User owner;
public Room(String roomName, List<User> users, User owner) {
this.roomName = roomName;
this.users = users;
this.owner = owner;
}
public Room() {
}
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
public Room(String roomName, User owner) {
this.roomName = roomName;
this.owner = owner;
this.users = new ArrayList<>();
}
public String getRoomName(){
return roomName;
}
public List<User> getUsers() {
return users;
}
public void setRoomName(String roomName) {
this.roomName = roomName;
}
public void setUsers(List<User> users) {
this.users = users;
}
}
package Data;
import java.io.Serializable;
public class User implements Serializable {
private String userName;
private String firstName;
private String lastName;
private String password;
public User(String userName, String firstName, String lastName, String password) {
this.userName = userName;
this.firstName = firstName;
this.lastName = lastName;
this.password = password;
}
public User() {
this.userName = "";
this.firstName = "";
this.lastName = "";
this.password = "";
}
public String getUserName() {
return userName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getPassword() {
return password;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setPassword(String password) {
this.password = password;
}
}
package SharedInterface;
import Data.Result;
import Data.User;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;
public interface ChatInterface extends Remote {
Result addChatRoom(String roomName, User owner) throws RemoteException;
Result deleteChatRoom(String roomName, User owner) throws RemoteException;
Result registerUser(String userName, String password, String firstName, String secondName) throws RemoteException;
Result loginToSystem(String userName, String password) throws RemoteException;
Result login(String userName, String password, String roomName) throws RemoteException;
Result logout(String userName, String roomName) throws RemoteException;
List<String> getAvailableChatRooms() throws RemoteException;
List<String> getClientsInChatRoom() throws RemoteException;
void sendMessageToClient(String sender, String receiver, String message) throws RemoteException;
void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException;
User getUserInfo(String username) throws RemoteException;
}
package SharedVariables;
import Data.User;
public class SharedVariables {
public static User user;
public static User getUser() {
return user;
}
public static void setUser(User user) {
SharedVariables.user = user;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.AddRoomForm">
<grid id="27dc6" binding="AddRoomPanel" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="607" height="400"/>
</constraints>
<properties>
<background color="-4924033"/>
</properties>
<border type="none"/>
<children>
<component id="348fe" class="javax.swing.JLabel" binding="lTitle">
<constraints>
<grid row="0" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="36" style="1"/>
<text value="Create a new chat room"/>
</properties>
</component>
<component id="9a271" class="javax.swing.JButton" binding="btnCancel">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Cancel"/>
</properties>
</component>
<component id="ccc6" class="javax.swing.JTextField" binding="tfRoomName">
<constraints>
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
</properties>
</component>
<component id="707da" class="javax.swing.JButton" binding="btnAdd">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Add"/>
</properties>
</component>
<component id="260ed" class="javax.swing.JLabel" binding="lName">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Room name"/>
</properties>
</component>
</children>
</grid>
</form>
package org.example;
import Data.Result;
import Data.User;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
public class AddRoomForm extends JDialog{
private JPanel AddRoomPanel;
private JLabel lTitle;
private JTextField tfRoomName;
private JLabel lName;
private JButton btnAdd;
private JButton btnCancel;
public AddRoomForm(ChatInterface chatInterface){
setTitle("Add chat room");
setContentPane(AddRoomPanel);
setMinimumSize(new Dimension(450, 474));
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
btnAdd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String roomName = tfRoomName.getText();
if(roomName.isEmpty()){
JOptionPane.showMessageDialog(AddRoomPanel, "please enter room name"
,"Failed", JOptionPane.ERROR_MESSAGE);
return;
}
try {
Result result = new Result();
User user = new User();
result = chatInterface.addChatRoom(roomName, SharedVariables.getUser());
if(result.isSuccess()){
JOptionPane.showMessageDialog(AddRoomPanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE);
dispose();
HomeForm home = new HomeForm(chatInterface);
// home.setVisible(true);
}
else{
JOptionPane.showMessageDialog(AddRoomPanel, result.getDescription()
,"Failed", JOptionPane.ERROR_MESSAGE);
}
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
HomeForm home = new HomeForm(chatInterface);
// home.setVisible(true);
}
});
setVisible(true);
}
}
package org.example;
import SharedInterface.ChatInterface;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
public class ChatClientService {
public static void main(String[] args) throws RemoteException, MalformedURLException, NotBoundException {
ChatInterface chatInterface = (ChatInterface) Naming.lookup("//localhost/ChatService");
try {
DashboardForm x = new DashboardForm(chatInterface);
x.setVisible(true);
}catch (Exception e){
System.out.println(e);
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.DashboardForm">
<grid id="27dc6" binding="DashPanel" 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>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties>
<background color="-4924033"/>
</properties>
<border type="none"/>
<children>
<component id="a18b9" class="javax.swing.JLabel" binding="lAdmin">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="36" style="1"/>
<text value="Welcome To Ali Chat App"/>
</properties>
</component>
<component id="fb905" class="javax.swing.JButton" binding="btnRegister">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Register"/>
</properties>
</component>
<component id="78b5" class="javax.swing.JButton" binding="btnLogin">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Login"/>
</properties>
</component>
</children>
</grid>
</form>
package org.example;
import SharedInterface.ChatInterface;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DashboardForm extends JFrame{
private JPanel DashPanel;
private JLabel lAdmin;
private JButton btnRegister;
private JButton btnLogin;
public DashboardForm(ChatInterface chatInterface){
setTitle("Dashboard");
setContentPane(DashPanel);
setMinimumSize(new Dimension(500, 429));
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
btnRegister.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
RegistrationForm register = new RegistrationForm(chatInterface);
// register.setVisible(true);
}
});
btnLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
LoginForm login = new LoginForm(chatInterface);
// login.setVisible(true);
}
});
setVisible(true);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.HomeForm">
<grid id="27dc6" binding="HomePanel" layout-manager="GridLayoutManager" row-count="10" column-count="3" 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="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="1bb98" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="0" column="0" row-span="10" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-4924033"/>
<font name="Segoe Print" size="18" style="1"/>
</properties>
<border type="none"/>
<children>
<component id="e1209" class="javax.swing.JLabel" binding="lWelcome">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Welcome to your"/>
</properties>
</component>
<component id="37d2" class="javax.swing.JLabel" binding="lText">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="account"/>
</properties>
</component>
<vspacer id="361a4">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="bd93d">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
<grid id="2f855" 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="1" column="2" row-span="9" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<hspacer id="432b7">
<constraints>
<grid row="9" column="1" 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="eca81" class="javax.swing.JButton" binding="btnAdd">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Add chat room"/>
</properties>
</component>
<component id="7eb59" class="javax.swing.JButton" binding="btnRemove">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Remove chat room"/>
</properties>
</component>
<component id="ce83c" class="javax.swing.JButton" binding="btnShow">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Show all rooms"/>
</properties>
</component>
<vspacer id="c437f">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="387df">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="63114">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="e288e">
<constraints>
<grid row="6" column="1" 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="2070" class="javax.swing.JButton" binding="btnLogout">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Logout"/>
</properties>
</component>
<vspacer id="acbbf">
<constraints>
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
package org.example;
import SharedInterface.ChatInterface;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class HomeForm extends JDialog {
private JPanel HomePanel;
private JLabel lWelcome;
private JLabel lText;
private JButton btnAdd;
private JButton btnRemove;
private JButton btnShow;
private JButton btnLogout;
public HomeForm(ChatInterface chatInterface){
setTitle("Home");
setContentPane(HomePanel);
setMinimumSize(new Dimension(450, 474));
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
btnAdd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
AddRoomForm addRoomForm = new AddRoomForm(chatInterface);
}
});
btnRemove.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
RemoveRoomForm removeRoomForm = new RemoveRoomForm(chatInterface);
}
});
btnShow.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
ShowRoomsForm show = new ShowRoomsForm(chatInterface);
// SwingUtilities.invokeLater(() -> {
// ShowRoomsForm show = new ShowRoomsForm(chatInterface);
// });
}
});
btnLogout.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
setVisible(true);
}
}
package org.example;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class ItemPanel extends JPanel {
private String itemName;
private JLabel nameLabel;
public ItemPanel(String itemName) {
this.itemName = itemName;
setLayout(new FlowLayout());
nameLabel = new JLabel(itemName);
nameLabel.addMouseListener(new ItemClickListener());
add(nameLabel);
}
private class ItemClickListener extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
// Handle item click event here
System.out.println(itemName+" is clicked ");
JOptionPane.showMessageDialog(ItemPanel.this, "Item clicked: " + itemName);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.LoginForm">
<grid id="27dc6" binding="LoginPanel" 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>
<xy x="20" y="20" width="500" height="446"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="58b39" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-4924033"/>
</properties>
<border type="none"/>
<children>
<component id="b3e80" class="javax.swing.JLabel" binding="lWelcome">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Welcome to the "/>
</properties>
</component>
<component id="b370f" class="javax.swing.JLabel" binding="lForm">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="24" style="1"/>
<text value="Login Form"/>
</properties>
</component>
<vspacer id="8d6e8">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="a0238">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
<hspacer id="9a42f">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="88342" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
</properties>
<border type="none"/>
<children>
<component id="b2f52" class="javax.swing.JLabel" binding="lUserName">
<constraints>
<grid row="1" 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>
<font name="Segoe Print" size="18" style="1"/>
<text value="User name"/>
</properties>
</component>
<component id="8778d" class="javax.swing.JTextField" binding="tfUserName">
<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">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
</properties>
</component>
<component id="b2068" class="javax.swing.JLabel" binding="lPassword">
<constraints>
<grid row="3" 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>
<font name="Segoe Print" size="18" style="1"/>
<text value="Password"/>
</properties>
</component>
<component id="2a3ce" class="javax.swing.JPasswordField" binding="tfPassword">
<constraints>
<grid row="4" 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>
<font name="Segoe Print" size="18" style="1"/>
</properties>
</component>
<component id="1d01a" class="javax.swing.JButton" binding="btnOK">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="OK"/>
</properties>
</component>
<component id="c9c81" class="javax.swing.JButton" binding="btnCancel">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Cancel"/>
</properties>
</component>
<vspacer id="ab7a0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="de7a6">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="b6024">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</children>
</grid>
</form>
package org.example;
import Data.Result;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
public class LoginForm extends JDialog{
private JLabel lUserName;
private JTextField tfUserName;
private JLabel lPassword;
private JPasswordField tfPassword;
private JButton btnOK;
private JButton btnCancel;
private JPanel LoginPanel;
private JLabel lWelcome;
private JLabel lForm;
public LoginForm(ChatInterface chatInterface) {
setTitle("Enter Your Account");
setContentPane(LoginPanel);
setMinimumSize(new Dimension(450, 474));
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
btnOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = tfUserName.getText();
String password = String.valueOf(tfPassword.getPassword());
if(username.isEmpty() || password.isEmpty()){
JOptionPane.showMessageDialog(LoginPanel, "please enter all fields"
,"try again", JOptionPane.ERROR_MESSAGE);
return;
}
try {
Result result = new Result();
result = chatInterface.loginToSystem(username,password);
if(result.isSuccess()){
JOptionPane.showMessageDialog(LoginPanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE);
SharedVariables.setUser(chatInterface.getUserInfo(username));
dispose();
HomeForm home = new HomeForm(chatInterface);
// home.setVisible(true);
}
else{
JOptionPane.showMessageDialog(LoginPanel, result.getDescription()
,"Failed", JOptionPane.ERROR_MESSAGE);
}
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
DashboardForm dashboard = new DashboardForm(chatInterface);
// dashboard.setVisible(true);
}
});
setVisible(true);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.RegistrationForm">
<grid id="27dc6" binding="RegisterPanel" layout-manager="GridLayoutManager" row-count="12" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="135" y="94" width="577" height="405"/>
</constraints>
<properties>
<background color="-206992"/>
</properties>
<border type="none"/>
<children>
<component id="ab649" class="javax.swing.JLabel" binding="lUsername">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="4" hsize-policy="0" anchor="10" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="User name"/>
</properties>
</component>
<component id="62b7a" class="javax.swing.JLabel" binding="lTitle">
<constraints>
<grid row="0" column="1" row-span="2" col-span="6" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="48" style="1"/>
<text value="Register"/>
</properties>
</component>
<component id="f9199" class="javax.swing.JLabel" binding="lFirstname">
<constraints>
<grid row="3" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="First name"/>
</properties>
</component>
<component id="f9f34" class="javax.swing.JTextField" binding="tfFirstname">
<constraints>
<grid row="3" column="1" row-span="2" col-span="6" 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>
<font name="Segoe Print" size="18" style="1"/>
<text value=""/>
</properties>
</component>
<component id="f203e" class="javax.swing.JLabel" binding="lLastname">
<constraints>
<grid row="5" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Last name"/>
</properties>
</component>
<component id="e79bd" class="javax.swing.JTextField" binding="tfLastname">
<constraints>
<grid row="5" column="1" row-span="2" col-span="6" 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>
<font name="Segoe Print" size="18" style="1"/>
<text value=""/>
</properties>
</component>
<component id="d04e0" class="javax.swing.JLabel" binding="lPassword">
<constraints>
<grid row="7" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Password"/>
</properties>
</component>
<component id="1743" class="javax.swing.JTextField" binding="tfUsername">
<constraints>
<grid row="2" column="1" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="2" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value=""/>
</properties>
</component>
<component id="c8be5" class="javax.swing.JPasswordField" binding="tfPass">
<constraints>
<grid row="7" column="1" row-span="2" col-span="6" 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>
<font name="Segoe Print" size="18" style="1"/>
<text value=""/>
</properties>
</component>
<component id="c75d2" class="javax.swing.JButton" binding="btnRegister">
<constraints>
<grid row="11" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Register"/>
</properties>
</component>
<component id="6953f" class="javax.swing.JButton" binding="btnCancel">
<constraints>
<grid row="11" column="4" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Cancel"/>
</properties>
</component>
<vspacer id="1e9d4">
<constraints>
<grid row="9" column="0" row-span="3" col-span="1" vsize-policy="4" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="61d13">
<constraints>
<grid row="9" column="1" row-span="2" col-span="6" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
package org.example;
import Data.Result;
import Data.User;
import SharedInterface.ChatInterface;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
public class RegistrationForm extends JDialog {
private JPasswordField tfPass;
private JButton btnRegister;
private JButton btnCancel;
private JPanel RegisterPanel;
private JTextField tfLastname;
private JLabel lLastname;
private JTextField tfFirstname;
private JTextField tfUsername;
private JLabel lUsername;
private JLabel lFirstname;
private JLabel lPassword;
private JLabel lTitle;
// private JLabel lImage;
public RegistrationForm(ChatInterface chatInterface){
setTitle("Create a new account");
setContentPane(RegisterPanel);
setMinimumSize(new Dimension(450, 474));
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
btnRegister.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = tfUsername.getText();
String lastname = tfLastname.getText();
String firstname = tfFirstname.getText();
String password = String.valueOf(tfPass.getPassword());
if(username.isEmpty() || lastname.isEmpty() || firstname.isEmpty() || password.isEmpty()){
JOptionPane.showMessageDialog(RegisterPanel, "please enter all fields"
,"try again", JOptionPane.ERROR_MESSAGE);
return;
}
try {
Result result = new Result();
result = chatInterface.registerUser(username,password,firstname,lastname);
if(result.isSuccess()){
JOptionPane.showMessageDialog(RegisterPanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE);
dispose();
LoginForm login = new LoginForm(chatInterface);
// login.setVisible(true);
}
else{
JOptionPane.showMessageDialog(RegisterPanel, result.getDescription()
,"Success", JOptionPane.ERROR_MESSAGE);
}
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
DashboardForm dashboard = new DashboardForm(chatInterface);
// dashboard.setVisible(true);
}
});
setVisible(true);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.RemoveRoomForm">
<grid id="27dc6" binding="RemovePanel" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="500" height="371"/>
</constraints>
<properties>
<background color="-4924033"/>
</properties>
<border type="none"/>
<children>
<component id="ce25f" class="javax.swing.JLabel" binding="lTitle">
<constraints>
<grid row="0" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="36" style="1"/>
<text value="Remove an existed room"/>
</properties>
</component>
<component id="a0097" class="javax.swing.JLabel" binding="lRoomName">
<constraints>
<grid row="1" 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>
<font name="Segoe Print" size="18" style="1"/>
<text value="Room name"/>
</properties>
</component>
<component id="51d2a" class="javax.swing.JTextField" binding="tfRoomName">
<constraints>
<grid row="1" column="1" row-span="1" col-span="3" 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>
<font name="Segoe Print" size="18" style="1"/>
</properties>
</component>
<component id="81816" class="javax.swing.JButton" binding="btnCancel">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Cancel"/>
</properties>
</component>
<component id="f5650" class="javax.swing.JButton" binding="btnRemove">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Segoe Print" size="18" style="1"/>
<text value="Remove"/>
</properties>
</component>
</children>
</grid>
</form>
package org.example;
import Data.Result;
import Data.User;
import SharedInterface.ChatInterface;
import SharedVariables.SharedVariables;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
public class RemoveRoomForm extends JDialog {
private JPanel RemovePanel;
private JLabel lTitle;
private JLabel lRoomName;
private JTextField tfRoomName;
private JButton btnRemove;
private JButton btnCancel;
public RemoveRoomForm(ChatInterface chatInterface){
setTitle("Remove an existed room");
setContentPane(RemovePanel);
setMinimumSize(new Dimension(450, 474));
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
btnRemove.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String roomName = tfRoomName.getText();
if(roomName.isEmpty()){
JOptionPane.showMessageDialog(RemovePanel, "please enter room name"
,"Failed", JOptionPane.ERROR_MESSAGE);
return;
}
try {
Result result = new Result();
result = chatInterface.deleteChatRoom(roomName, SharedVariables.getUser());
if(result.isSuccess()){
JOptionPane.showMessageDialog(RemovePanel, result.getDescription()
,"Success", JOptionPane.INFORMATION_MESSAGE);
dispose();
HomeForm home = new HomeForm(chatInterface);
// home.setVisible(true);
}
else{
JOptionPane.showMessageDialog(RemovePanel, result.getDescription()
,"Failed", JOptionPane.ERROR_MESSAGE);
}
} catch (RemoteException ex) {
throw new RuntimeException(ex);
}
}
});
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
HomeForm home = new HomeForm(chatInterface);
}
});
setVisible(true);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.example.ShowRoomsForm">
<grid id="27dc6" 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="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="b766" binding="scroll">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="cf056" binding="ShowPanel" 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/>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</scrollpane>
</children>
</grid>
</form>
package org.example;
import SharedInterface.ChatInterface;
import javax.swing.*;
import java.awt.*;
public class ShowRoomsForm extends JDialog{
private JScrollPane scroll;
private JPanel ShowPanel;
public ShowRoomsForm(ChatInterface chatInterface) {
setTitle("Show all rooms");
setPreferredSize(new Dimension(450, 474)); // Set the preferred size for the ShowPanel
ShowPanel = new JPanel();
ShowPanel.setLayout(new BoxLayout(ShowPanel, BoxLayout.Y_AXIS));
String[] itemList = {"Item 1", "Item 4", "Item 5", "Item 3", "Item 4", "Item 5", "Item 2", "Item 3", "Item 4", "Item 5"};
for (String item : itemList) {
ItemPanel itemPanel = new ItemPanel(item);
ShowPanel.add(itemPanel);
}
scroll = new JScrollPane(ShowPanel);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
setContentPane(scroll);
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
pack();
setVisible(true);
}
// public ShowRoomsForm(ChatInterface chatInterface){
// setTitle("Show all rooms");
//// setContentPane(scroll);
//// setMinimumSize(new Dimension(450, 474));
//// setModal(true);
//// setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// ShowPanel = new JPanel();
//
// ShowPanel.setLayout(new BoxLayout(ShowPanel, BoxLayout.Y_AXIS));
// scroll = new JScrollPane(ShowPanel);
//
// setContentPane(scroll);
// setMinimumSize(new Dimension(450, 474));
// setModal(true);
// setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// String[] itemList = {"Item 1", "Item 4", "Item 5", "Item 3", "Item 4", "Item 5", "Item 2", "Item 3", "Item 4", "Item 5"};
// JPanel itemContainer = new JPanel();
// itemContainer.setLayout(new BoxLayout(itemContainer, BoxLayout.Y_AXIS));
// for (String item : itemList) {
// ItemPanel itemPanel = new ItemPanel(item);
// itemContainer.add(itemPanel);
// }
// scroll.setViewportView(itemContainer);
// pack();
// setVisible(true);
// }
}
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="ChatServer" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="e25cce4c-cf2f-4ddb-9eec-8aa7eed92b1a" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/ChatServiceImpl.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Interface" />
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2XqPpXPKus52LXh4WBh7I7Wfsu0" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true"
}
}]]></component>
<component name="RunManager">
<configuration name="ChatServer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.example.ChatServer" />
<module name="ChatServer" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="org.example.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.ChatServer" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="e25cce4c-cf2f-4ddb-9eec-8aa7eed92b1a" name="Changes" comment="" />
<created>1699353823525</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1699353823525</updated>
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
</project>
\ No newline at end of file
grant {
permission java.security.AllPermission;
};
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ChatServer</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
package Data;
public class Message {
}
package Data;
import java.io.Serializable;
public class Result implements Serializable {
private boolean isSuccess;
private String description;
public Result(boolean isSuccess, String description) {
this.isSuccess = isSuccess;
this.description = description;
}
public Result() {
this.description="";
this.isSuccess = false;
}
public void setSuccess(boolean success) {
isSuccess = success;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isSuccess() {
return isSuccess;
}
public String getDescription() {
return description;
}
}
package Data;
import javax.jws.soap.SOAPBinding;
import java.util.ArrayList;
import java.util.List;
public class Room {
private String roomName;
private List<User> users;
private User owner;
public Room(String roomName, List<User> users, User owner) {
this.roomName = roomName;
this.users = users;
this.owner = owner;
}
public Room() {
}
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
public Room(String roomName, User owner) {
this.roomName = roomName;
this.owner = owner;
this.users = new ArrayList<>();
}
public String getRoomName(){
return roomName;
}
public List<User> getUsers() {
return users;
}
public void setRoomName(String roomName) {
this.roomName = roomName;
}
public void setUsers(List<User> users) {
this.users = users;
}
}
package Data;
import java.io.Serializable;
public class User implements Serializable {
private String userName;
private String firstName;
private String lastName;
private String password;
public User(String userName, String firstName, String lastName, String password) {
this.userName = userName;
this.firstName = firstName;
this.lastName = lastName;
this.password = password;
}
public User() {
this.userName = "";
this.firstName = "";
this.lastName = "";
this.password = "";
}
public String getUserName() {
return userName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getPassword() {
return password;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setPassword(String password) {
this.password = password;
}
}
package SharedInterface;
import Data.Result;
import Data.User;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;
public interface ChatInterface extends Remote {
Result addChatRoom(String roomName, User owner) throws RemoteException;
Result deleteChatRoom(String roomName, User owner) throws RemoteException;
Result registerUser(String userName, String password, String firstName, String secondName) throws RemoteException;
Result loginToSystem(String userName, String password) throws RemoteException;
Result login(String userName, String password, String roomName) throws RemoteException;
Result logout(String userName, String roomName) throws RemoteException;
List<String> getAvailableChatRooms() throws RemoteException;
List<String> getClientsInChatRoom() throws RemoteException;
void sendMessageToClient(String sender, String receiver, String message) throws RemoteException;
void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException;
User getUserInfo(String username) throws RemoteException;
}
package org.example;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class ChatServer {
public static void main(String[] args) throws RemoteException {
System.setProperty("java.security.policy", "./ChatServicePolicy.policy");
System.setSecurityManager(new RMISecurityManager());
Registry reg = LocateRegistry.createRegistry(1099);
ChatServiceImpl chatServiceImp = new ChatServiceImpl();
String ChatSVC = "ChatService";
reg.rebind(ChatSVC, chatServiceImp);
System.out.println("Chat Server Ready and Use default port for RMI Service called " + ChatSVC);
}
}
package org.example;
import Data.Result;
import Data.Room;
import Data.User;
import SharedInterface.ChatInterface;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;
public class ChatServiceImpl extends UnicastRemoteObject implements ChatInterface {
private List<Room> chatRooms;
private List<User> registeredUsers;
private List<User> loggedInUsers;
protected ChatServiceImpl() throws RemoteException {
super();
chatRooms = new ArrayList<>();
registeredUsers = new ArrayList<>();
loggedInUsers = new ArrayList<>();
}
@Override
public Result addChatRoom(String roomName, User owner) throws RemoteException {
Result result = new Result();
for(Room room : chatRooms){
if(room.getRoomName().equals(roomName)){
result.setDescription("Chat room "+roomName+" is already exist");
result.setSuccess(false);
return result;
}
}
Room room = new Room(roomName,owner);
room.getUsers().add(owner);
System.out.println("user: "+owner.getUserName()+" "+owner.getFirstName()+" add chat room named: "+roomName);
chatRooms.add(room);
for (Room room1 : chatRooms){
System.out.println("Room name: "+room1.getRoomName()+" the owner is:" + owner.getUserName());
}
result.setDescription("Chat room "+roomName+" is created successfully");
result.setSuccess(true);
return result;
}
@Override
public Result deleteChatRoom(String roomName,User owner ) throws RemoteException {
Result result = new Result();
for(Room room : chatRooms){
if(room.getRoomName().equals(roomName)){
if(room.getOwner().getUserName().equals(owner.getUserName())&&room.getOwner().getPassword().equals(owner.getPassword())){
chatRooms.remove(room);
result.setDescription("Chat room "+roomName+" is deleted successfully");
result.setSuccess(true);
}
else{
result.setDescription("Permission denied!!!");
result.setSuccess(false);
}
return result;
}
}
result.setDescription("Chat room "+roomName+" does not exist");
result.setSuccess(false);
return result;
}
@Override
public Result registerUser(String userName, String password, String firstName, String secondName) throws RemoteException {
System.out.println("there is user want to register");
Result result = new Result();
for(User user : registeredUsers){
if(user.getUserName().equals(userName)) {
result.setSuccess(false);
result.setDescription("UserName is already exist");
return result;
}
}
User newuser = new User(userName,firstName,secondName,password);
registeredUsers.add(newuser);
result.setSuccess(true);
result.setDescription("registration done successfully");
System.out.println("Done");
for(User user: registeredUsers){
System.out.println(user.getUserName()+" "+user.getPassword()+ " "+user.getFirstName()+" "+user.getLastName());
}
return result;
}
@Override
public Result loginToSystem(String userName, String password) throws RemoteException {
Result result = new Result();
for(User user : registeredUsers){
if(user.getUserName().equals(userName)){
if(user.getPassword().equals(password)){
loggedInUsers.add(user);
result.setSuccess(true);
result.setDescription("log in done successfully");
}
else{
result.setSuccess(false);
result.setDescription("user name and password does not match !!!");
}
return result;
}
}
result.setSuccess(false);
result.setDescription("user name does not exist");
return result;
}
@Override
public Result login(String userName, String password, String roomName) throws RemoteException {
Result result = new Result();
for(Room room : chatRooms){
if(room.getRoomName()==roomName){
for (User user : room.getUsers()){
if(user.getUserName() == userName && user.getPassword() == password){
result.setDescription("Logged in successfully");
result.setSuccess(true);
return result;
}
}
result.setDescription("Permission denied !!!");
result.setSuccess(false);
return result;
}
}
result.setDescription("Room name does not exist !!!");
result.setSuccess(false);
return result;
}
@Override
public Result logout(String userName, String roomName) throws RemoteException {
Result result = new Result();
for(Room room : chatRooms){
if(room.getRoomName() == roomName){
for(User user : room.getUsers()){
if(user.getUserName() == userName){
room.getUsers().remove(user);
result.setDescription("logout done successfully");
result.setSuccess(true);
}
else{
result.setDescription("User name does not exist in this room !!!");
result.setSuccess(false);
}
return result;
}
}
}
result.setDescription("Room name does not exist!!!");
result.setSuccess(false);
return result;
}
@Override
public List<String> getAvailableChatRooms() throws RemoteException {
return null;
}
@Override
public List<String> getClientsInChatRoom() throws RemoteException {
return null;
}
@Override
public void sendMessageToClient(String sender, String receiver, String message) throws RemoteException {
}
@Override
public void sendMessageToRoom(String sender, String roomName, String message) throws RemoteException {
}
@Override
public User getUserInfo(String username) throws RemoteException {
for (User user : registeredUsers){
if(user.getUserName().equals(username)){
return user;
}
}
return null;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment