-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirst_atm.java
More file actions
executable file
·209 lines (160 loc) · 5.27 KB
/
Copy pathfirst_atm.java
File metadata and controls
executable file
·209 lines (160 loc) · 5.27 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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* @(#)first_atm.java
*
*
*
*
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class first_atm extends JFrame implements ActionListener{
JTextField txtuser=new JTextField(25);
JPasswordField txtpass=new JPasswordField(25);
JLabel lbluser=new JLabel("Username: ");
JLabel lblpass=new JLabel("Pin Number: ");
JButton btnOk=new JButton(new ImageIcon("register.jpg"));
JButton btnRegister=new JButton(new ImageIcon("button.jpg"));
//JButton btnBlock = new JButton("Lock Account >>");
Connection cn;
//ResultSet rs;
Statement st;
PreparedStatement ps;
public first_atm(){
JPanel pane=new JPanel();
pane.setLayout(null);
//----Adding Components into your Frame
pane.add(txtuser);
pane.add(txtpass);
pane.add(lbluser);
pane.add(lblpass);
pane.add(btnOk);
pane.add(btnRegister);
//pane.add(btnBlock);
//-----Setting the location of the components
lbluser.setBounds(10,20,80,20);
lblpass.setBounds(10,40,80,20);
txtuser.setBounds(100,20,100,20);
txtpass.setBounds(100,40,100,20);
btnOk.setBounds(50,70,75,20);
btnRegister.setBounds(125,70,83,20);
//btnBlock.setBounds(55,90,150,20);
//-----Adding the an actionlistener to the buttons
btnOk.addActionListener(this);
btnRegister.addActionListener(this);
//btnBlock.addActionListener(this);
//btnBlock.setForeground(Color.yellow);
//btnBlock.setBackground(Color.black);
setContentPane(pane);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel lbl = new JLabel(new ImageIcon("back.jpg"));
lbl.setBounds(0,0,250,150);
pane.add(lbl);
//connection
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn = DriverManager.getConnection("jdbc:odbc:project");
}catch(ClassNotFoundException e) {
System.err.println("Failed to load driver");
e.printStackTrace();
}catch(SQLException e){
System.err.println("Unable to connect");
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e){
Object source=e.getSource();
if(source==btnOk){
try{
String str1=txtuser.getText();
String str2=txtpass.getText();
if((str1.length()==0 || str2.length()==0)){
JOptionPane.showMessageDialog(null,"Connot be Process","WARNING",JOptionPane.WARNING_MESSAGE);
}
else{
st=cn.createStatement();
String strUser="";
String strPass="";
ResultSet rs=st.executeQuery("SELECT * FROM tbl_list WHERE UserName='"+str1+"'");
while(rs.next()){
strUser=rs.getString(1);
strPass=rs.getString(4);
}
st.close();
if(strUser.equals(str1)){
if(strPass.equals(str2)){
JOptionPane.showMessageDialog(null,"Welcome "+txtuser.getText(),"Welcome",JOptionPane.INFORMATION_MESSAGE);
third_atm panel = new third_atm();
panel.setSize(330,300);
panel.setVisible(true);
panel.setResizable(false);
panel.setLocation(400,250);
dispose();
}else{
JOptionPane.showMessageDialog(null,"Username found but the password is incorrect!","Security Pass",JOptionPane.WARNING_MESSAGE);
txtpass.requestFocus(true);
}
}else{
JOptionPane.showMessageDialog(null,"Username is incorrect!","Security Pass",JOptionPane.WARNING_MESSAGE);
txtuser.requestFocus(true);
}
}
}catch(SQLException w){
}
}else if(source==btnRegister){
second_atm panel = new second_atm();
panel.setSize(370,400);
panel.setVisible(true);
panel.setResizable(false);
panel.setLocation(400,250);
dispose();
}
/* else if(source == btnBlock){
int n=JOptionPane.showConfirmDialog(null,"If you lock this account,you cannot access this Anymore.Are you sure you want to Lock this account?","Warning",JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION){
try{
st=cn.createStatement();
String strUser="";
String strPass="";
ResultSet rs=st.executeQuery("SELECT * FROM
WHERE UserName='"+txtuser.getText()+"'");
while(rs.next()){
strUser=rs.getString(1);
strPass=rs.getString(5);
}
if(strUser.equals(txtuser.getText())){
if(strPass.equals(txtpass.getText())){
ps = cn.prepareStatement("DELETE FROM tbl_Info WHERE UserName ='"+ txtuser.getText() + "'");
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Your Account has been successfully Lock.","ATM",JOptionPane.INFORMATION_MESSAGE);
txtuser.requestFocus(true);
txtuser.setText("");
txtpass.setText("");
}else{
JOptionPane.showMessageDialog(null,"Username found but the Pin Number is incorrect!","Security Pass",JOptionPane.WARNING_MESSAGE);
txtpass.requestFocus(true);
}
}else{
JOptionPane.showMessageDialog(null,"Username is incorrect!","Security Pass",JOptionPane.WARNING_MESSAGE);
txtuser.requestFocus(true);
}
}
catch(SQLException s){
System.out.print("SQL statement is not executed!");
}
catch(Exception j){
j.printStackTrace();
}
}
}*/
}
public static void main(String[]args){
first_atm log=new first_atm();
log.setLocation(400,250);
log.setSize(250,150);
log.setTitle("Log-In");
log.setResizable(false);
log.setVisible(true);
}
}