-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdepositScreen.java
More file actions
91 lines (73 loc) · 3.17 KB
/
depositScreen.java
File metadata and controls
91 lines (73 loc) · 3.17 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class depositScreen {
private JFrame frame;
private JPanel panel;
private JLabel jl = new JLabel();
private JTextField jt = new JTextField("00", 30);
JLabel prompt = new JLabel("How much would like to deposit\n");
depositScreen(){
String currUser = ATM.name.getText();
jt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
}
});
jt.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
jt.setText("");
}
});
JButton back = new JButton("BACK");
back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
frame.dispose();
new menuScreen();
}
});
JButton confirm = new JButton("CONFIRM");
confirm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try{
Statement myStat = database.getConn().createStatement();
String query = "SELECT * FROM mydb.atm_data WHERE Name='"+currUser+"'";
ResultSet myRs = myStat.executeQuery(query);
if (myRs.next()){
Float startBal = myRs.getFloat("Balance");
Float wAmount = Float.valueOf(jt.getText()).floatValue();
Float newBal = startBal + wAmount;
String sql = "update mydb.atm_data "+ "set Balance = " + newBal + " where Name = '" + currUser + "'";
myStat.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "Thank you for your time", "Deposit Complete", 1);
new viewScreen();
}
}
catch(SQLException e){
e.printStackTrace();
}
catch(NumberFormatException n){
JOptionPane.showMessageDialog(null, "No letters", "Input mismatch", 1);
}
}
});
frame = new JFrame("DEPOSIT");
panel = new JPanel();
JPanel tpanel = new JPanel();
JPanel bpanel = new JPanel();
frame.setSize(600,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.getContentPane().setBackground(Color.LIGHT_GRAY);
frame.getContentPane().add(tpanel, BorderLayout.NORTH);
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.getContentPane().add(bpanel, BorderLayout.SOUTH);
tpanel.add(prompt);
bpanel.add(jl);
bpanel.add(confirm);
panel.add(jt);
panel.add(back);
}
}