-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.java
182 lines (157 loc) · 3.26 KB
/
user.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
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
package myproject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.awt.event.*;
import javax.swing.*;
public class user extends JFrame implements ActionListener,ItemListener {
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9;
JButton b1,b2,b3;
JComboBox cb;
JTextField t1,t2,t3,t4,t5,t6;
JRadioButton r1,r2;
Connection con;
Statement stmt;
user()
{
setLayout(null);
setSize(1000,1000);
l1=new JLabel("Create User");
l2=new JLabel("User Type");
l3=new JLabel("Full Name ");
l4=new JLabel("User id");
l5=new JLabel("Password");
l6=new JLabel("Re-Enter Password");
l7=new JLabel("Department");
l8=new JLabel("Roll no.");
l9=new JLabel("Phone No.");
b1=new JButton("Add New");
b2=new JButton("Create");
b3=new JButton("Cancel");
cb=new JComboBox();
cb.addItem("Select");
cb.addItem("Computer Science");
cb.addItem("Electronics and Communication");
cb.addItem("Information technology");
cb.addItem("Mechanical");
t1=new JTextField();
t2=new JTextField();
t3=new JTextField();
t4=new JTextField();
t5=new JTextField();
t6=new JTextField();
r1=new JRadioButton("Faculty");
r2=new JRadioButton("Student");
ButtonGroup bg=new ButtonGroup();
bg.add(r1);
bg.add(r2);
add(b1);
add(b2);
add(b3);
add(l1);
add(l2);
add(l3);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(l7);
add(l8);
add(l9);
add(cb);
add(r1);
add(r2);
add(t1);
add(t2);
add(t3);
add(t4);
add(t5);
add(t6);
l1.setBounds(400,50,200,30);
l2.setBounds(100,150,200,20);
r1.setBounds(300,150,200,20);
r2.setBounds(500,150,200,20);
l3.setBounds(100,200,200,20);
t1.setBounds(300,200,200,20);
l4.setBounds(100,250,200,20);
t2.setBounds(300,250,200,20);
l5.setBounds(100,300,200,20);
t3.setBounds(300,300,200,20);
l6.setBounds(100,350,200,20);
t4.setBounds(300,350,200,20);
l7.setBounds(100,400,200,20);
cb.setBounds(300,400,200,20);
l8.setBounds(100,450,200,20);
t5.setBounds(300,450,200,20);
l9.setBounds(100,500,200,20);
t6.setBounds(300,500,200,20);
b1.setBounds(100,550,200,20);
b2.setBounds(400,550,200,20);
b3.setBounds(700,550,200,20);
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/projectdb","root","rupali");
stmt=con.createStatement();
}
catch(Exception e1)
{}
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
r1.addItemListener(this);
setVisible (true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t3.setText("");
t1.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t2.setText("");
cb.setSelectedIndex(0);
r2.setSelected(true);
}
if(e.getSource()==b2)
{
try{
String type="";
if(r1.isSelected())
type="Faculty";
else
type="Student";
String s1="insert into user values('"+type+"','"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+cb.getSelectedItem()+"','"+t5.getText()+"','"+t6.getText()+"')";
JOptionPane.showMessageDialog(this,s1);
stmt.executeUpdate(s1);
}
catch(Exception e1)
{
System.out.println("Exception :"+e1);
}
}
if(e.getSource()==b3)
{
System.exit(1);
}
}
public void itemStateChanged(ItemEvent i)
{
if(i.getSource()==r1)
{
t5.setVisible(false);
}
if(i.getSource()==r2)
{
t5.setVisible(true);
}
}
public static void main(String ar[])
{
new user();
}
}