-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCorrectAcc.java
More file actions
91 lines (76 loc) · 2.39 KB
/
CorrectAcc.java
File metadata and controls
91 lines (76 loc) · 2.39 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
package login;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class CorrectAcc extends JPanel implements ActionListener
{
JLabel corr,toCorr,orilabel,oripassword;
JTextField corrText,acc;
JPasswordField jp;
JButton sure1,sure2,back;
JPanel npanel,spanel;
DataBaseconnection dbc=new DataBaseconnection();
ResultSet res;
String id="middle";//记录账号位置
public CorrectAcc()
{
npanel=new JPanel();
spanel=new JPanel();
//实例化
corr=new JLabel("请输入您要修改的账号 :",JLabel.CENTER);
toCorr=new JLabel("请修改,然后点击确定即可:",JLabel.CENTER);
orilabel=new JLabel("账号 :",JLabel.CENTER);oripassword=new JLabel("密码 :",JLabel.CENTER);
corrText=new JTextField(10);acc=new JTextField(10);
jp=new JPasswordField(10);
sure1=new JButton("确定");sure2=new JButton("确定修改");
//add to contailor
npanel.add(corr);npanel.add(corrText);npanel.add(sure1);
add(npanel);
add(toCorr);
spanel.setLayout(new GridLayout(2,2));
spanel.add(orilabel);spanel.add(acc);
spanel.add(oripassword);spanel.add(jp);
//添加监听器
sure1.addActionListener(this);sure2.addActionListener(this);
add(spanel);
add(sure2);
setLayout(new GridLayout(4,1));
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==sure1)
{
res=dbc.executeQuery("select * from stuacc where account='"+corrText.getText()+"'");
try {
if (res.next())
{
id=res.getString(3);
acc.setText(res.getString(1));jp.setText(res.getString(2));
}
else
{
JOptionPane.showMessageDialog(null,"Sorry!暂无该账号的信息,请确认好后重新输入","Wrong Usernumber",JOptionPane.ERROR_MESSAGE);
}
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}
else if (e.getSource()==sure2)
{
System.out.println(id);
dbc.executeUpdate("update stuacc set account='"+acc.getText()+"',password='"+jp.getText()+"' where id='"+id+"'");
JOptionPane.showMessageDialog(null,"修改成功!","已保存",JOptionPane.OK_OPTION);
corrText.setText("");acc.setText("");jp.setText("");
}
}
}