-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetreive1.java
More file actions
132 lines (115 loc) · 2.97 KB
/
Retreive1.java
File metadata and controls
132 lines (115 loc) · 2.97 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
125
126
127
128
129
130
131
132
package railwayreservation;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JTextField;
public class Retreive1 extends JDialog implements ActionListener{
private JTextField ps;
private JTextField an;
private JTextField qe;
private JTextField us;
JButton btl,gp;
String uans,pass,tans;
public Retreive1() {
getContentPane().setLayout(null);
getContentPane().setBackground(Color.pink);
JLabel lblNewLabel = new JLabel("Username");
lblNewLabel.setBounds(76, 53, 65, 14);
getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Question");
lblNewLabel_1.setBounds(76, 111, 46, 14);
getContentPane().add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Answer");
lblNewLabel_2.setBounds(76, 171, 46, 14);
getContentPane().add(lblNewLabel_2);
gp = new JButton("Get Password");
gp.setBounds(174, 216, 127, 23);
getContentPane().add(gp);
JLabel lblNewLabel_3 = new JLabel("Password");
lblNewLabel_3.setBounds(76, 294, 65, 14);
getContentPane().add(lblNewLabel_3);
btl = new JButton("Back to Login");
btl.setBounds(174, 366, 127, 23);
getContentPane().add(btl);
ps = new JTextField();
ps.setEditable(false);
ps.setBounds(177, 291, 86, 20);
getContentPane().add(ps);
ps.setColumns(10);
an = new JTextField();
an.setBounds(174, 168, 86, 20);
getContentPane().add(an);
an.setColumns(10);
qe = new JTextField();
qe.setEditable(false);
qe.setBounds(174, 108, 86, 20);
getContentPane().add(qe);
qe.setColumns(10);
us = new JTextField(Loginform.user);
us.setEditable(false);
us.setBounds(174, 50, 86, 20);
getContentPane().add(us);
us.setColumns(10);
btl.addActionListener(this);
gp.addActionListener(this);
fillinfo();
setSize(500,600);
setVisible(true);
}
void fillinfo()
{
String s="Select * from signup where userid=?";
Connection con=MyConnection.connect();
try
{
PreparedStatement ps=con.prepareStatement(s);
ps.setString(1, Loginform.user);
ResultSet rs=ps.executeQuery();
while(rs.next())
{
pass=rs.getString("password");
tans=rs.getString("answer");
qe.setText(rs.getString("quest"));
}
}
catch(SQLException se)
{
se.printStackTrace();
}
}
public static void main(String[] args) {
new Retreive1();
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent e) {
Object ob=e.getSource();
if(ob==btl)
{
new Loginform();
dispose();
}else if(ob==gp)
{
uans=new String(an.getText());
if(tans.equals(uans))
{
ps.setText(pass);
}
else
{
JOptionPane.showMessageDialog(null, "wrong answer");
an.getText();
an.requestFocusInWindow();
}
}
// TODO Auto-generated method stub
}
}