forked from VatsalBhuva11/OOM-MiniProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
84 lines (70 loc) · 2.83 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Main {
static int running = 1;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
do {
System.out.println();
System.out.println("Create a new user or log in or exit? (1/2/3) : ");
int choice = sc.nextInt();
if (choice == 1) {
System.out.println("Enter your user name: ");
String name = sc.next();
System.out.println("Enter the password: ");
String password = sc.next();
User u = new User(name, password);
int flag = 1;
for (User check : User.users) {
if (check.username.equals(name)) {
System.out.println("Username already exists. Please try again.");
flag = 0;
break;
}
}
if (flag == 1)
User.users.add(u);
} else if (choice == 2) {
System.out.println("Enter your user name: ");
String name = sc.next();
System.out.println("Enter the password: ");
String password = sc.next();
int flag = 1;
if (name.equals("test") && password.equals("test")) {
System.out.println("Welcome " + name);
flag = 0;
running = 0;
} else {
for (User u : User.users) {
if (u.username.equals(name) && u.password.equals(password)) {
System.out.println("Welcome " + name);
flag = 0;
running = 0;
}
}
}
if (flag == 1) {
System.out.println("Sorry !! " + name + " \nEither username or password is wrong ");
} else {
JFrame jFrame = new JFrame();
jFrame.setTitle("Home Page");
Add a = new Add();
Container cPane = jFrame.getContentPane();
Newclass template = new Newclass(a, cPane);
jFrame.setSize(template.getSize());
jFrame.setResizable(false);
cPane.add(template);
jFrame.setVisible(true);
jFrame.setLocationRelativeTo(null);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} else {
System.out.println("Thank you for using our application");
running = 0;
}
sc.nextLine();
} while (running == 1);
sc.close();
}
}