-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI4.java
More file actions
97 lines (77 loc) · 2.91 KB
/
GUI4.java
File metadata and controls
97 lines (77 loc) · 2.91 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
import java.awt.event.ActionEvent;
import java.sql.*;
import java.awt.event.ActionListener;
import javax.swing.*;
class GUI4 {
public static void newScreen2 ()
{
JFrame jf=new JFrame ("Add Accountant");
JLabel namelabel = new JLabel("Name:");
namelabel.setBounds(20,25,150,10);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(13,55,150,10);
JTextField userText =new JTextField();
userText.setBounds(80,20,200,20);
JPasswordField passwordText= new JPasswordField();
passwordText.setBounds(80,50,200,20);
JLabel emaillabel =new JLabel("Email:");
emaillabel.setBounds(20,85,150,10);
JTextField email = new JTextField();
email.setBounds(80,80,200,20);
JLabel phoneNumber =new JLabel("Phone:");
phoneNumber.setBounds(20,110,150,10);
JTextField phone = new JTextField();
phone.setBounds(80,110,200,20);
JButton jb1 = new JButton("Add");
jb1.setBounds(100,140,100, 50);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String firstName = userText.getText();
String emailId = email.getText();
String mobileNumber = phone.getText();
int len = mobileNumber.length();
String password = passwordText.getText();
if (len != 10) {
JOptionPane.showMessageDialog(jb1, "Enter a valid mobile number");
}
try {
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/accountant", "root", "root123");
String query = "INSERT INTO account values('" +firstName + "','" + password + "','" + emailId + "','" + mobileNumber + "')";
Statement sta = connection.createStatement();
int x = sta.executeUpdate(query);
if (x == 0) {
JOptionPane.showMessageDialog(jb1, "This is alredy exist");
} else {
JOptionPane.showMessageDialog(jb1,
"Accountant Added");
}
connection.close();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
JButton jb2 = new JButton("Back");
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GUI3 obj = new GUI3();
obj.Screen();
jf.dispose();
}
});
jb2.setBounds(100,200,100, 50);
jf.add(namelabel);
jf.add(passwordLabel);
jf.add(emaillabel);
jf.add(userText);
jf.add(passwordText);
jf.add(email);
jf.add(phoneNumber);
jf.add(phone);
jf.add(jb1);
jf.add(jb2);
jf.setSize(400,400);
jf.setLayout(null);
jf.setVisible(true);
}
}