FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Uni__LibraryManagementJavaGUI/src/code/AddAdminForm.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
/
AddAdminForm.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
145 lines (125 loc) · 4.51 KB
Breadcrumbs
Uni__LibraryManagementJavaGUI
/
src
/
code
/
AddAdminForm.java
Copy path
File metadata and controls
145 lines (125 loc) · 4.51 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
package
code
;
import
javax
.
swing
.*;
import
java
.
awt
.*;
import
java
.
awt
.
event
.
MouseAdapter
;
import
java
.
awt
.
event
.
MouseEvent
;
import
java
.
awt
.
event
.
MouseListener
;
import
java
.
awt
.
event
.
MouseMotionAdapter
;
public
class
AddAdminForm
extends
JFrame
{
// Ui variables
private
JPanel
addAdminFrame
;
private
JPanel
labelUsername
;
private
JLabel
labelLogo
;
private
JComboBox
comboBoxAdmins
;
private
JButton
buttonChangeToAdmin
;
private
JLabel
labelChangeToAdmin
;
private
JLabel
labelAbout
;
/**
* Constructor method,
*/
public
AddAdminForm
() {
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
(
addAdminFrame
);
// set main frame
// Title and size of frame
setTitle
(
"Add Admin Form"
);
setSize
(
500
,
600
);
// set Icon for JFrame
setIconImage
(
new
ImageIcon
(
"src/images/mOMIDs.png"
).
getImage
());
fillComboBox
();
// fill combobox of users
mouseClickActions
();
// mouse click actions to object in frame
mouseMoveActions
();
// mouse move actions to object in frame
}
/**
* fillComboBox method for filling combobox with users
*/
private
void
fillComboBox
() {
String
[][]
users
=
Manager
.
getAdminsUsers
()[
2
];
comboBoxAdmins
.
removeAllItems
();
for
(
String
[]
user
:
users
) {
comboBoxAdmins
.
addItem
(
new
ComboItem
(
user
[
0
],
user
[
0
]));
}
}
/**
* mouseMoveActions method for setting move actions of mouse for any object on frame
*/
private
void
mouseMoveActions
() {
buttonChangeToAdmin
.
addMouseMotionListener
(
new
MouseMotionAdapter
() {
@
Override
public
void
mouseMoved
(
MouseEvent
e
) {
super
.
mouseMoved
(
e
);
buttonChangeToAdmin
.
setCursor
(
Cursor
.
getPredefinedCursor
(
Cursor
.
HAND_CURSOR
));
buttonChangeToAdmin
.
setBackground
(
new
Color
(
135
,
69
,
211
));
}
});
comboBoxAdmins
.
addMouseMotionListener
(
new
MouseMotionAdapter
() {
@
Override
public
void
mouseMoved
(
MouseEvent
e
) {
super
.
mouseMoved
(
e
);
comboBoxAdmins
.
setCursor
(
Cursor
.
getPredefinedCursor
(
Cursor
.
HAND_CURSOR
));
buttonChangeToAdmin
.
setBackground
(
new
Color
(
234
,
35
,
123
));
}
});
labelAbout
.
addMouseMotionListener
(
new
MouseMotionAdapter
() {
@
Override
public
void
mouseMoved
(
MouseEvent
e
) {
super
.
mouseMoved
(
e
);
labelAbout
.
setCursor
(
Cursor
.
getPredefinedCursor
(
Cursor
.
HAND_CURSOR
));
}
});
}
/**
* mouseMoveActions method for setting click actions of mouse for any object on frame
*/
private
void
mouseClickActions
() {
buttonChangeToAdmin
.
addMouseListener
(
new
MouseAdapter
() {
public
void
mouseClicked
(
MouseEvent
e
) {
if
(
comboBoxAdmins
.
getItemCount
() !=
0
) {
// find user in combobox and change it to admin
String
userToAdmin
= ((
ComboItem
)
comboBoxAdmins
.
getSelectedItem
()).
getValue
();
Manager
.
promoteToAdmin
(
userToAdmin
);
JOptionPane
.
showMessageDialog
(
null
,
String
.
format
(
"User '%s' promoted to admin !"
,
userToAdmin
),
"Admin Adding Dialog"
,
JOptionPane
.
INFORMATION_MESSAGE
);
fillComboBox
();
}
}
});
MouseListener
ml2
;
ml2
=
new
MouseAdapter
() {
public
void
mousePressed
(
MouseEvent
e
) {
AboutForm
aboutForm
=
new
AboutForm
();
}
};
labelAbout
.
addMouseListener
(
ml2
);
}
/**
* main method for testing the frame, it's useless in general
*/
public
static
void
main
(
String
[]
args
) {
AddAdminForm
com
=
new
AddAdminForm
();
}
}
/**
* ComboItem class for redesign it combo items and user it to get value of current selection of combobox
*/
class
ComboItem
{
private
final
String
key
;
private
final
String
value
;
public
ComboItem
(
String
key
,
String
value
) {
this
.
key
=
key
;
this
.
value
=
value
;
}
@
Override
public
String
toString
() {
return
key
;
}
public
String
getKey
() {
return
key
;
}
public
String
getValue
() {
return
value
;
}
}
Back
|
FazBrowse Home
|
New Git URL