Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedFarid612 authored Sep 9, 2021
1 parent 9070df6 commit 80619fc
Show file tree
Hide file tree
Showing 62 changed files with 10,515 additions and 0 deletions.
Binary file added dist/Frexie.jar
Binary file not shown.
22 changes: 22 additions & 0 deletions src/frexie/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package frexie;

import view.GlobalChat;

public class Controller {

public static String globalString = "";
public static boolean receivedMessage = false;
public static String currentUsername;
public static User currentUser;
public static GlobalChat globalChat = null;
public static int globalChatParticipants;
public static String currentMsg;
public static boolean flag = false;
public static String gender;
public static String status;
public static String selectedFriend;
public static boolean flagGlobalChat=false;
public static String currentChatPartner;
public static User selectedUser;

}
62 changes: 62 additions & 0 deletions src/frexie/DataChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

package frexie;

public class DataChecker {

public static boolean verifyUser(String email,String password)
{
for(int i=0;i<FileLoader.users.size();i++)
{
if(email.equalsIgnoreCase(FileLoader.users.get(i).getEmail()) && password.equals(FileLoader.users.get(i).getPassword()))
{
Controller.currentUsername=FileLoader.users.get(i).getUserName();
Controller.currentUser=FileLoader.users.get(i);
Controller.gender=FileLoader.users.get(i).getGender();
Controller.status=FileLoader.users.get(i).getStatus();
return true;
}
}
return false;
}

public static boolean confirmPassword(String password,String confirmPassword)
{if(password.equals(confirmPassword))return true;return false;}



public static boolean isUsedUsername(String username)
{
for(int i=0;i<FileLoader.users.size();i++)
{
if(username.equalsIgnoreCase(FileLoader.users.get(i).getUserName()))
return true;

}
return false;
}


public static boolean isUsedEmail(String username)
{
for(int i=0;i<FileLoader.users.size();i++)
{
if(username.equalsIgnoreCase(FileLoader.users.get(i).getEmail()))
return true;

}
return false;
}

public static boolean checkUser(String username)
{
for(int i=0;i<FileLoader.users.size();i++)
{
if(!FileLoader.users.get(i).getUserName().equalsIgnoreCase(Controller.currentUser.getUserName()) && FileLoader.users.get(i).getUserName().equalsIgnoreCase(username) )
return false;

}

return true;
}

}
181 changes: 181 additions & 0 deletions src/frexie/FileHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package frexie;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class FileHandler {

public static void deactivateUser() {

int x;
try {
BufferedWriter bw = new BufferedWriter(new FileWriter("users.txt"));
for (x = 0; x < FileLoader.users.size(); x++) {
if (!FileLoader.users.get(x).getUserName().equalsIgnoreCase(Controller.currentUser.getUserName())) {
bw.write(FileLoader.users.get(x).getUserName() + "," + FileLoader.users.get(x).getFirstName()
+ "," + FileLoader.users.get(x).getLastName() + "," + FileLoader.users.get(x).getFullName()
+ "," + FileLoader.users.get(x).getEmail() + "," + FileLoader.users.get(x).getPassword()
+ "," + FileLoader.users.get(x).getGender() + "," + Integer.toString(FileLoader.users.get(x).getCountFriends()) + ","
+ FileLoader.users.get(x).getStatus() + "," + FileLoader.users.get(x).getState() + "\n");
}

}
bw.close();
} catch (Exception ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure books.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}

}

public static void UpdateUsersFile() {
int x;
try {
BufferedWriter bw = new BufferedWriter(new FileWriter("users.txt"));
for (x = 0; x < FileLoader.users.size(); x++) {
if (!FileLoader.users.get(x).getUserName().equalsIgnoreCase(Controller.currentUser.getUserName())) {
bw.write(FileLoader.users.get(x).getUserName() + "," + FileLoader.users.get(x).getFirstName()
+ "," + FileLoader.users.get(x).getLastName() + "," + FileLoader.users.get(x).getFullName()
+ "," + FileLoader.users.get(x).getEmail() + "," + FileLoader.users.get(x).getPassword()
+ "," + FileLoader.users.get(x).getGender() + "," + Integer.toString(FileLoader.users.get(x).getCountFriends()) + ","
+ FileLoader.users.get(x).getStatus() + "," + FileLoader.users.get(x).getState() + "\n");
} else {
bw.write(Controller.currentUser.getUserName() + "," + Controller.currentUser.getFirstName()
+ "," + Controller.currentUser.getLastName() + "," + Controller.currentUser.getFullName()
+ "," + Controller.currentUser.getEmail() + "," + Controller.currentUser.getPassword()
+ "," + Controller.currentUser.getGender() + "," + Integer.toString(Controller.currentUser.getCountFriends()) + ","
+ Controller.currentUser.getStatus() + "," + Controller.currentUser.getState() + "\n");
}
}
bw.close();
} catch (Exception ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure books.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
public static void addToUsersFile(String userName, String firstName, String lastName, String fullName, String email, String password, String gender, int countFriends) {
User user = new User();
user.setFirstName(firstName);
user.setUserName(userName);
user.setCountFriends(countFriends);
user.setEmail(email);
user.setFullName(fullName);
user.setLastName(lastName);
user.setPassword(password);
user.setGender(gender);
user.setStatus(" ");
user.setState("true");
FileLoader.users.add(user);
Controller.currentUser = user;
Controller.currentUsername = user.getUserName();
UpdateUsersFile();
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
public static void createNewUserFile() {

try {
File file = new File(Controller.currentUsername + ".txt");
file.createNewFile();
} catch (IOException ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure UserName.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}

}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
public static void addFriend(String username) {

try {
int x;
ArrayList<String> temp = new ArrayList<String>();
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(Controller.currentUser.getUserName() + ".txt"));
for (x = 0; x < Controller.currentUser.getFriendsNames().size(); x++) {
bw.write(Controller.currentUser.getFriendsNames().get(x) + "\n");
}
bw.write(username + "\n");
bw.close();
} catch (Exception ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure UserName.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}
/////////////////////////////////////////////
temp = FileLoader.loadFriends(username);
BufferedWriter bw2 = new BufferedWriter(new FileWriter(username + ".txt"));
for (x = 0; x < temp.size(); x++) {
bw2.write(temp.get(x) + "\n");
}
bw2.write(Controller.currentUser.getUserName() + "\n");
bw2.close();
} catch (IOException ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure UserName.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}

}

//////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
public static void addFirstFriend(String username) {
BufferedWriter bw2 = null;
try {
bw2 = new BufferedWriter(new FileWriter(username + ".txt"));
bw2.write("1" + "\n");
bw2.close();
} catch (IOException ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure UserName.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}
}



public static void deleteFriend(String username)
{

try {
int x;
ArrayList<String> temp = new ArrayList<String>();
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(Controller.currentUser.getUserName() + ".txt"));
for (x = 0; x < Controller.currentUser.getFriendsNames().size(); x++) {
if(!Controller.currentUser.getFriendsNames().get(x).equalsIgnoreCase(username)) bw.write(Controller.currentUser.getFriendsNames().get(x) + "\n");
}

bw.close();
} catch (Exception ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure UserName.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}
/////////////////////////////////////////////
temp = FileLoader.loadFriends(username);
BufferedWriter bw2 = new BufferedWriter(new FileWriter(username + ".txt"));
for (x = 0; x < temp.size(); x++) {
if(!temp.get(x).equalsIgnoreCase(Controller.currentUser.getUserName())) bw2.write(temp.get(x) + "\n");
}
bw2.close();
} catch (IOException ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure UserName.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}



}
}
78 changes: 78 additions & 0 deletions src/frexie/FileLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

package frexie;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class FileLoader {

public static ArrayList<User> users = new ArrayList<>();


public static void FileLoading() {
try {


users.clear();

BufferedReader br = new BufferedReader(new FileReader("users.txt"));
String temp;
while ((temp = br.readLine()) != null) {

User tempUser = new User();
StringTokenizer st = new StringTokenizer(temp, ",");
while (st.hasMoreTokens()) {
tempUser.setUserName(st.nextToken());
tempUser.setFirstName(st.nextToken());
tempUser.setLastName(st.nextToken());
tempUser.setFullName(st.nextToken());
tempUser.setEmail(st.nextToken());
tempUser.setPassword(st.nextToken());
tempUser.setGender(st.nextToken());
tempUser.setCountFriends(Integer.parseInt(st.nextToken()));
tempUser.setStatus(st.nextToken());
String tempState=st.nextToken();
tempUser.setState(tempState);
users.add(tempUser);
}
}
br.close();
} catch (Exception ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure users.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
return;
}
}
public static ArrayList loadFriends(String fileName)
{

ArrayList<String> friends=new ArrayList();
try {
BufferedReader br = new BufferedReader(new FileReader(fileName+".txt"));
String temp;

while ((temp = br.readLine()) != null) {

StringTokenizer st = new StringTokenizer(temp, "\n");
while (st.hasMoreTokens()) {
String tempString=st.nextToken();
friends.add(tempString);
}
}
br.close();
} catch (Exception ex) {
ImageIcon xMark = new ImageIcon("xMark50.png");
JOptionPane.showMessageDialog(null, "File not found!\nplease make sure thisuser's.txt is in program folder and restart the application", "Operation failed", JOptionPane.INFORMATION_MESSAGE, xMark);
}

return friends;
}




}
51 changes: 51 additions & 0 deletions src/frexie/Finder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package frexie;

import java.util.ArrayList;

public class Finder {

public static User FindFriend(String username) {

for (int i = 0; i < FileLoader.users.size(); i++) {
if (FileLoader.users.get(i).getUserName().equalsIgnoreCase(username)) {
return FileLoader.users.get(i);
}
}
return null;
}

public static boolean isAlreadyFriend(String Username) {

for (int i = 0; i < Controller.currentUser.getFriendsNames().size(); i++) {
if (Controller.currentUser.getFriendsNames().get(i).equalsIgnoreCase(Username)) {
return true;
}
}
return false;
}

public static boolean isOnline(String Username) {

if (Controller.selectedUser.getState().equalsIgnoreCase("true")) {
return true;
}

return false;
}

public static ArrayList<User> loadOnlineFriends() {
FileLoader.FileLoading();
ArrayList<String> temp = Controller.currentUser.getFriendsNames();
ArrayList<User> temp2 = new ArrayList<>();
for (int i = 0; i < temp.size(); i++) {
String tempString = temp.get(i);
for (int j = 0; j < FileLoader.users.size(); j++) {
if (tempString.trim().equalsIgnoreCase(FileLoader.users.get(j).getUserName()) && FileLoader.users.get(j).getState().equalsIgnoreCase("true") ) {
temp2.add(FileLoader.users.get(j));
}
}
}
return temp2;
}

}
Loading

0 comments on commit 80619fc

Please sign in to comment.