-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibrarianForm.java
More file actions
193 lines (171 loc) · 7.3 KB
/
LibrarianForm.java
File metadata and controls
193 lines (171 loc) · 7.3 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package libraryManagement;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class LibrarianForm extends JFrame {
static LibrarianForm frame;
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JPasswordField passwordField;
///launching
public static void main(String[] args) {
try {
frame = new LibrarianForm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
//creating frame
public LibrarianForm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 450);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JLabel lblAddLibrarian = new JLabel("Add Librarian");
lblAddLibrarian.setForeground(Color.DARK_GRAY);
lblAddLibrarian.setFont(new Font("URW Gothic L", Font.BOLD, 20));
JLabel lblName = new JLabel("Name:");
lblName.setFont(new Font("Purisa", Font.PLAIN, 15));
JLabel lblPassword = new JLabel("Password:");
lblPassword.setFont(new Font("Purisa", Font.PLAIN, 15));
JLabel lblEmail = new JLabel("Email:");
lblEmail.setFont(new Font("Purisa", Font.PLAIN, 15));
JLabel lblAddress = new JLabel("Address:");
lblAddress.setFont(new Font("Purisa", Font.PLAIN, 15));
JLabel lblCity = new JLabel("City:");
lblCity.setFont(new Font("Purisa", Font.PLAIN, 15));
JLabel lblContactNo = new JLabel("Contact No:");
lblContactNo.setFont(new Font("Purisa", Font.PLAIN, 15));
textField = new JTextField();
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setColumns(10);
textField_4 = new JTextField();
textField_4.setColumns(10);
passwordField = new JPasswordField();
JButton btnNewButton = new JButton("Add Librarian");
btnNewButton.setFont(new Font("Purisa",Font.PLAIN,15));
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name=textField.getText();
String password=String.valueOf(passwordField.getPassword());
String email=textField_1.getText();
String address=textField_2.getText();
String city=textField_3.getText();
String contact=textField_4.getText();
int i=LibrarianDao.save(name, password, email, address, city, contact);
if(i>0){
JOptionPane.showMessageDialog(LibrarianForm.this,"Librarian added successfully!");
AdminSuccess.main(new String[]{});
frame.dispose();
}else{
JOptionPane.showMessageDialog(LibrarianForm.this,"Sorry, unable to save!");
}
}
});
btnNewButton.setForeground(Color.DARK_GRAY);
JButton btnBack = new JButton("Back");
btnBack.setFont(new Font("Purisa", Font.PLAIN, 15));
btnBack.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AdminSuccess.main(new String[]{});
frame.dispose();
}
});
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(20)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(lblPassword, GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
.addComponent(lblName)
.addComponent(lblEmail, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addComponent(lblAddress, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lblCity, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addComponent(lblContactNo, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(58)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(textField_4, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(textField_3, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(textField_2, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(textField, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(passwordField))
.addContainerGap(107, Short.MAX_VALUE))
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap(151, Short.MAX_VALUE)
.addComponent(lblAddLibrarian)
.addGap(144))
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap(160, Short.MAX_VALUE)
.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
.addGap(117))
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap(200, Short.MAX_VALUE)
.addComponent(btnBack)
.addGap(169))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblAddLibrarian)
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblName)
.addGap(18)
.addComponent(lblPassword))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblEmail)
.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblAddress)
.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblCity)
.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblContactNo)
.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
.addComponent(btnBack)
.addGap(19))
);
contentPane.setLayout(gl_contentPane);
}
}