FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Uni__LibraryManagementJavaGUI/src/code/LoginForm.java at master · bestmahdi2/Uni__LibraryManagementJavaGUI · GitHub
bestmahdi2
/
Uni__LibraryManagementJavaGUI
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Uni__LibraryManagementJavaGUI
/
src
/
code
/
LoginForm.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
155 lines (134 loc) · 5.59 KB
Breadcrumbs
Uni__LibraryManagementJavaGUI
/
src
/
code
/
LoginForm.java
Copy path
File metadata and controls
155 lines (134 loc) · 5.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package
code
;
import
javax
.
swing
.*;
import
java
.
awt
.*;
import
java
.
awt
.
event
.*;
import
java
.
util
.
Objects
;
public
class
LoginForm
extends
JFrame
{
// Ui variables
private
JPanel
loginFrame
;
private
JPanel
labelUsername
;
private
JTextField
fieldUsername
;
private
JPasswordField
fieldPassword
;
private
JLabel
labelSignIn
;
private
JLabel
labelLogo
;
private
JButton
buttonSignIn
;
private
JLabel
labelUser
;
private
JLabel
labelPass
;
private
JLabel
labelErrorLogin
;
private
JLabel
fieldSignUpClick
;
private
String
password
;
private
String
username
;
// main forms
AdminForm
mainPageAdmin
;
UserForm
mainPageUser
;
/**
* Constructor method,
*/
public
LoginForm
() {
setResizable
(
false
);
// forbidden user to resize the frame
setLocationRelativeTo
(
null
);
// to be opened in center
try
{
// change its look to Microsoft Windows
UIManager
.
setLookAndFeel
(
UIManager
.
getSystemLookAndFeelClassName
());
}
catch
(
Exception
e
) {
e
.
printStackTrace
();
}
setContentPane
(
loginFrame
);
// set main frame
// Title and size of frame
setTitle
(
"Login Form"
);
setSize
(
500
,
600
);
// Action after closing this frame
setDefaultCloseOperation
(
WindowConstants
.
EXIT_ON_CLOSE
);
// set Icon for JFrame
setIconImage
(
new
ImageIcon
(
"src/images/mOMIDs.png"
).
getImage
());
mouseClickActions
();
// mouse click actions to object in frame
mouseMoveActions
();
// mouse move actions to object in frame
setVisible
(
true
);
// show the frame and windows
}
public
String
[]
getLoginInfo
() {
return
new
String
[]{
username
,
password
};
}
/**
* mouseMoveActions method for setting move actions of mouse for any object on frame
*/
private
void
mouseMoveActions
() {
buttonSignIn
.
addMouseMotionListener
(
new
MouseMotionAdapter
() {
@
Override
public
void
mouseMoved
(
MouseEvent
e
) {
super
.
mouseMoved
(
e
);
buttonSignIn
.
setCursor
(
Cursor
.
getPredefinedCursor
(
Cursor
.
HAND_CURSOR
));
}
});
fieldSignUpClick
.
addMouseMotionListener
(
new
MouseMotionAdapter
() {
@
Override
public
void
mouseMoved
(
MouseEvent
e
) {
super
.
mouseMoved
(
e
);
fieldSignUpClick
.
setCursor
(
Cursor
.
getPredefinedCursor
(
Cursor
.
HAND_CURSOR
));
}
});
}
/**
* mouseMoveActions method for setting click actions of mouse for any object on frame
*/
private
void
mouseClickActions
() {
buttonSignIn
.
addActionListener
(
new
ActionListener
() {
@
Override
public
void
actionPerformed
(
ActionEvent
e
) {
// get text in fields
username
=
fieldUsername
.
getText
();
password
=
String
.
valueOf
(
fieldPassword
.
getPassword
());
// empty error label
labelErrorLogin
.
setText
(
" "
);
labelErrorLogin
.
setForeground
(
Color
.
RED
);
if
(
Objects
.
equals
(
username
,
""
))
labelErrorLogin
.
setText
(
"⚠️ Username can't be empty !"
);
else
if
(
Objects
.
equals
(
password
,
""
))
labelErrorLogin
.
setText
(
"⚠️ Password can't be empty !"
);
else
{
// if username and password weren't empty
if
(
Manager
.
loginCheck
(
username
,
password
)) {
// if credentials were correct
labelErrorLogin
.
setForeground
(
Color
.
GREEN
);
labelErrorLogin
.
setText
(
"Logging in ..."
);
ActionListener
taskPerformer
=
new
ActionListener
() {
public
void
actionPerformed
(
ActionEvent
evt
) {
setVisible
(
false
);
// hide login form
Manager
.
setUsername
(
username
);
// set username
// check if this person is admin or user
boolean
admin
=
false
;
for
(
String
[]
user
:
Manager
.
getAdminsUsers
()[
1
]) {
if
(
Objects
.
equals
(
user
[
0
],
username
)) {
admin
=
true
;
break
;
}
}
// show proper form
if
(
admin
)
mainPageAdmin
=
new
AdminForm
();
else
{
mainPageUser
=
new
UserForm
();
}
}
};
Timer
timer
=
new
Timer
(
1000
,
taskPerformer
);
timer
.
setRepeats
(
false
);
timer
.
start
();
}
else
labelErrorLogin
.
setText
(
"⚠️ Username or password is wrong !"
);
}
}
});
fieldSignUpClick
.
addMouseListener
(
new
MouseAdapter
() {
// show signup frame
public
void
mouseClicked
(
MouseEvent
e
) {
SignUpForm
signUpForm
=
new
SignUpForm
();
labelErrorLogin
.
setText
(
" "
);
labelErrorLogin
.
setForeground
(
Color
.
RED
);
fieldUsername
.
setText
(
""
);
fieldPassword
.
setText
(
""
);
setVisible
(
false
);
}
});
}
/**
* main method for testing the frame, it's useless in general
*/
public
static
void
main
(
String
[]
args
) {
LoginForm
loginForm
=
new
LoginForm
();
}
}
Back
|
FazBrowse Home
|
New Git URL