-
Notifications
You must be signed in to change notification settings - Fork 0
/
TugasPraktikumModul8.java
136 lines (113 loc) · 3.93 KB
/
TugasPraktikumModul8.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package TugasModul8;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PerpustakaanDigital {
private JLabel labelJudul;
private JTextField textPassword;
private JTextField textEmail;
private JTextArea textLibrary;
private JLabel labelEmail;
private JLabel labelPassword;
private JButton submitButton;
private JButton clearButton;
private JPanel panel;
public static void main(String[] args) {
JFrame frame = new JFrame("Peminjaman Buku");
frame.setContentPane(new PerpustakaanDigital().panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public PerpustakaanDigital() {
submitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
BusinessLogic businessLogic = new BusinessLogic(textEmail.getText(), textPassword.getText());
boolean status = businessLogic.checkCredential();
if(status == true)
{
textLibrary.setText("\nWelcome " + businessLogic.getRoles() +
"\nLogged it as user email " + businessLogic.getEmail() + "\n" +
businessLogic.getEmail() + " meminjam buku : \n" +
"Buku 1 : " + businessLogic.getSubject1() +
"\nBuku 2 : " + businessLogic.getSubject2() +
"\nTanggal peminjaman : " + businessLogic.getDate() + "\n");
}
else
{
textLibrary.setText("\nInvalid Login");
}
textLibrary.getText();
}
});
clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textPassword.setText("");
textEmail.setText("");
textLibrary.setText("");
}
});
}
}
class BusinessLogic{
private String email;
private String password;
private String roles;
private String subject1, subject2, date;
private String[][] data = new String[2][3];
private String[][] histories = new String[2][4];
public BusinessLogic(String email, String password) {
this.email = email;
this.password = password;
String[][] data = {
{"syahirakelompok29@gmail.com", "kel29", "superAdmin"},
{"farizkelompok29@gmail.com", "kel29", "user"}
};
String[][] histories = {
{"syahirakelompok29@gmail.com", "Fisika Dasar", "Dasar Komputer dan Pemrograman", "23-04-2021"},
{"farizkelompok29@gmail.com", "Dasar Komputer dan Pemrograman", "Konsep Jaringan Komputer", "24-04-2021"}
};
this.data = data;
this.histories = histories;
}
public String getEmail() {
return email;
}
public String getRoles() {
return roles;
}
public String getSubject1() {
return subject1;
}
public String getSubject2() {
return subject2;
}
public String getDate() {
return date;
}
public boolean checkCredential()
{
for(int i = 0; i < data.length; i++ )
{
if(data[i][0].equals(email))
{
if(data[i][1].equals(password))
{
roles = data[i][2];
}
for(int j = 0; j < histories.length; j++){
if(histories[i][0].equals(email))
{
subject1 = histories[i][1];
subject2 = histories[i][2];
date = histories[i][3];
}
}
return true;
}
}
return false;
}
}