-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentForm.java
More file actions
186 lines (156 loc) · 6.03 KB
/
StudentForm.java
File metadata and controls
186 lines (156 loc) · 6.03 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
/**
*
* @author deepu
*/
/*
public class StudentForm {
}
*/
import java.awt.EventQueue;
import javax.swing.JFrame;
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.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class StudentForm {
private static JFrame frame;
private JTextField textField;
private JPasswordField passwordField;
private JTextField textField_1;
private JTextField textField_2;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
StudentForm window = new StudentForm();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public StudentForm() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 18));
frame.setBounds(100, 100, 640, 460);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel lblAddNewLibrarian = new JLabel("Add New Student");
lblAddNewLibrarian.setForeground(Color.GRAY);
lblAddNewLibrarian.setFont(new Font("Tahoma", Font.PLAIN, 28));
JLabel lblName = new JLabel("Name :");
lblName.setFont(new Font("Tahoma", Font.PLAIN, 18));
JLabel lblPassword = new JLabel("Password :");
lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 18));
JLabel lblEmail = new JLabel("Email :");
lblEmail.setFont(new Font("Tahoma", Font.PLAIN, 18));
JLabel lblContactNumber = new JLabel("Contact Number :");
lblContactNumber.setFont(new Font("Tahoma", Font.PLAIN, 18));
textField = new JTextField();
textField.setColumns(10);
passwordField = new JPasswordField();
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setColumns(10);
JButton btnAddLibrarian = new JButton("Add Student");
btnAddLibrarian.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnAddLibrarian.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String studentname=textField.getText();
String password=String.valueOf(passwordField.getPassword());
String email=textField_1.getText();
String studentcontact=textField_2.getText();
int fine = 0;
int i=StudentDao.save(studentname, password, email, studentcontact, fine);
if(i>0){
JOptionPane.showMessageDialog(StudentForm.frame,"Student added successfully!");
LibrarianSuccess.main(new String[]{});
frame.dispose();
}else{
JOptionPane.showMessageDialog(StudentForm.frame,"Sorry, unable to save!");
}
}
});
JButton btnBack = new JButton("Back");
btnBack.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
LibrarianSuccess.main(new String[]{});
frame.dispose();
}
});
GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(189)
.addComponent(lblAddNewLibrarian))
.addGroup(groupLayout.createSequentialGroup()
.addGap(73)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblName)
.addComponent(lblPassword)
.addComponent(lblEmail)
.addComponent(lblContactNumber))
.addGap(33)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addComponent(textField_2)
.addComponent(textField_1)
.addComponent(passwordField)
.addComponent(textField, GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)))
.addGroup(groupLayout.createSequentialGroup()
.addGap(234)
.addComponent(btnAddLibrarian)))
.addContainerGap(137, Short.MAX_VALUE))
.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
.addContainerGap(513, Short.MAX_VALUE)
.addComponent(btnBack)
.addContainerGap())
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(25)
.addComponent(lblAddNewLibrarian)
.addGap(36)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblName)
.addGap(33)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblPassword)
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(35)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblEmail)
.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(34)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblContactNumber)
.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(39)
.addComponent(btnAddLibrarian)
.addGap(18)
.addComponent(btnBack)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
frame.getContentPane().setLayout(groupLayout);
}
}