-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStudentLeave.java
109 lines (89 loc) · 3.38 KB
/
StudentLeave.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
package university.management.system;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import com.toedter.calendar.JDateChooser;
import java.awt.event.*;
public class StudentLeave extends JFrame implements ActionListener {
Choice crollno, ctime;
JDateChooser dcdate;
JButton submit, cancel;
StudentLeave() {
setSize(500, 550);
setLocation(550, 100);
setLayout(null);
getContentPane().setBackground(Color.WHITE);
JLabel heading = new JLabel("Apply Leave (Student)");
heading.setBounds(40, 50, 300, 30);
heading.setFont(new Font("Tahoma", Font.BOLD, 20));
add(heading);
JLabel lblrollno = new JLabel("Search by Roll Number");
lblrollno.setBounds(60, 100, 200, 20);
lblrollno.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(lblrollno);
crollno = new Choice();
crollno.setBounds(60, 130, 200, 20);
add(crollno);
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from student");
while(rs.next()) {
crollno.add(rs.getString("rollno"));
}
} catch (Exception e) {
e.printStackTrace();
}
JLabel lbldate = new JLabel("Date");
lbldate.setBounds(60, 180, 200, 20);
lbldate.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(lbldate);
dcdate = new JDateChooser();
dcdate.setBounds(60, 210, 200, 25);
add(dcdate);
JLabel lbltime = new JLabel("Time Duration");
lbltime.setBounds(60, 260, 200, 20);
lbltime.setFont(new Font("Tahoma", Font.PLAIN, 18));
add(lbltime);
ctime = new Choice();
ctime.setBounds(60, 290, 200, 20);
ctime.add("Full Day");
ctime.add("Half Day");
add(ctime);
submit = new JButton("Submit");
submit.setBounds(60, 350, 100, 25);
submit.setBackground(Color.BLACK);
submit.setForeground(Color.WHITE);
submit.addActionListener(this);
submit.setFont(new Font("Tahoma", Font.BOLD, 15));
add(submit);
cancel = new JButton("Cancel");
cancel.setBounds(200, 350, 100, 25);
cancel.setBackground(Color.BLACK);
cancel.setForeground(Color.WHITE);
cancel.addActionListener(this);
cancel.setFont(new Font("Tahoma", Font.BOLD, 15));
add(cancel);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == submit) {
String rollno = crollno.getSelectedItem();
String date = ((JTextField) dcdate.getDateEditor().getUiComponent()).getText();
String duration = ctime.getSelectedItem();
String query = "insert into studentleave values('"+rollno+"', '"+date+"', '"+duration+"')";
try {
Conn c = new Conn();
c.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Leave Confirmed");
setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
} else {
setVisible(false);
}
}
public static void main(String[] args) {
new StudentLeave();
}
}