-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI7.java
More file actions
122 lines (104 loc) · 3.82 KB
/
GUI7.java
File metadata and controls
122 lines (104 loc) · 3.82 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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class GUI7 {
public static void Screen7() {
JFrame jf=new JFrame ("Add Student");
JLabel namelabel = new JLabel("Name:");
namelabel.setBounds(20,25,150,10);
JTextField userText =new JTextField();
userText.setBounds(80,20,200,20);
JLabel emaillabel =new JLabel("Email:");
emaillabel.setBounds(20,70,150,10);
JTextField email = new JTextField();
email.setBounds(80,70,200,20);
JLabel phoneNumber =new JLabel("Phone:");
phoneNumber.setBounds(20,120,150,10);
JTextField phone = new JTextField();
phone.setBounds(80,120,200,20);
JLabel courselabel =new JLabel("Course:");
courselabel.setBounds(20,170,150,10);
JTextField course = new JTextField();
course.setBounds(80,170,200,20);
JLabel fee =new JLabel("Fee:");
fee.setBounds(20,220,150,10);
JTextField feetext = new JTextField();
feetext.setBounds(80,220,200,20);
JLabel paidtext =new JLabel("Paid:");
paidtext.setBounds(20,270,150,10);
JTextField paid = new JTextField();
paid.setBounds(80,270,200,20);
JLabel DueText =new JLabel("Due:");
DueText.setBounds(20,310,150,10);
JTextField due = new JTextField();
due.setBounds(80,310,200,20);
JLabel CityText =new JLabel("City:");
CityText.setBounds(20,360,150,10);
JTextField City = new JTextField();
City.setBounds(80,360,200,20);
JButton jb1 = new JButton("Add Student");
jb1.setBounds(20,400,150,60);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String firstName = userText.getText();
String emailId = email.getText();
String mobileNumber = phone.getText();
String Course=course.getText();
String Fee =feetext.getText();
String Paid =paid.getText();
String Due = due.getText();
String city = City.getText();
int len = mobileNumber.length();
if (len != 10) {
JOptionPane.showMessageDialog(jb1, "Enter a valid mobile number");
}
try {
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "root123");
String query = "INSERT INTO Students values('" +firstName + "','" +emailId +"','" + mobileNumber + "','" +Course + "','" + Fee + "','" +Paid+ "','" +Due+ "','" +city + "')";
Statement sta = connection.createStatement();
int x = sta.executeUpdate(query);
if (x == 0) {
JOptionPane.showMessageDialog(jb1, "This is alredy exist");
} else {
JOptionPane.showMessageDialog(jb1,
"Student Details Added");
}
connection.close();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
JButton jb2 = new JButton("Back");
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GUI6 obj = new GUI6();
obj.Screen6();
jf.dispose();
}
});
jb2.setBounds(200,400,150,60);
jf.add(namelabel);
jf.add(userText);
jf.add(email);
jf.add(emaillabel);
jf.add(phoneNumber);
jf.add(phone);
jf.add(courselabel);
jf.add(course);
jf.add(fee);
jf.add(feetext);
jf.add(paidtext);
jf.add(paid);
jf.add(DueText);
jf.add(due);
jf.add(CityText);
jf.add(City);
jf.add(jb1);
jf.add(jb2);
jf.setSize(400,600);
jf.setLayout(null);
jf.setVisible(true);
}
}