-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFacebookForm
More file actions
124 lines (111 loc) · 3.84 KB
/
FacebookForm
File metadata and controls
124 lines (111 loc) · 3.84 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
package Business;
import java.awt.Container;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import DBManage.ConnectDB;
import java.awt.CardLayout;
public class FacebookForm extends JFrame {
JFrame f = new JFrame("The Frame");
JLabel lbSignUp = new JLabel("Sign Up");
JTextField tfFirstName = new JTextField(10);
JPasswordField tfPass = new JPasswordField(10);
JButton btnSignUp = new JButton("Sign Up");
JButton btnChange = new JButton("Change Pass");
JButton btnDelete = new JButton("Delete");
JRadioButton rbMale=new JRadioButton("Male");
JRadioButton rbFemale=new JRadioButton("Female");
JButton btnList = new JButton("List");
ButtonGroup br= new ButtonGroup();
PreparedStatement ps;
Connection conn;
ResultSet rs;
public FacebookForm() {
//tao 1 container de add cac component vao
// this.getContentPane().;
f.setLocation(300, 300);
f.setLayout(new FlowLayout());
Container cont = f.getContentPane();
//cont.setLayout(new LayoutManager());
cont.add(lbSignUp);
cont.add(tfFirstName);
cont.add(tfPass);
br.add(rbMale);
br.add(rbFemale);
cont.add(rbMale);
cont.add(rbFemale);
//Hobbies : Game Music
cont.add(btnSignUp);
btnSignUp.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ConnectDB cnn = new ConnectDB();
String gender="";
if(rbMale.isSelected()) gender=rbMale.getText();
else gender = rbFemale.getText();
cnn.executeDB(" Exec sp_AddAccount '"+tfFirstName.getText()+"','"+tfPass.getText()+"','"+gender+"'");
}
});
cont.add(btnChange);
btnChange.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ConnectDB cnn = new ConnectDB();
int record= cnn.executeDB("Update Account set Password='"+tfPass.getText()+"' where Username ='"+tfFirstName.getText()+"' ");
if(record>0) JOptionPane.showMessageDialog(null, "Change Pass sucessfully!");
else JOptionPane.showMessageDialog(null, "Error");
}
});
cont.add(btnDelete);
btnDelete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ConnectDB cnn = new ConnectDB();
String gender="";
if(rbMale.isSelected()) gender=rbMale.getText();
else gender = rbFemale.getText();
int record = cnn.executeDB("Delete Account where Username ='"+tfFirstName.getText()+"'");
if(record>0) JOptionPane.showMessageDialog(null, "Delete Account sucessfully!");
else JOptionPane.showMessageDialog(null, "Error");
}
});
cont.add(btnList);
btnList.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ConnectDB cnn = new ConnectDB();
String gender="";
if(rbMale.isSelected()) gender=rbMale.getText();
else gender = rbFemale.getText();
rs = cnn.ListAccount("exec [sp_SelectByGender] '"+gender+"' ");
try {
while(rs.next()) {
System.out.println("Username ="+rs.getString("Username"));
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} }
);
f.setSize(200,200);
f.pack();
f.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//new FacebookForm();
new FacebookForm();
}
}