-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastCash.java
More file actions
139 lines (98 loc) · 4.33 KB
/
FastCash.java
File metadata and controls
139 lines (98 loc) · 4.33 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
package bank.management.system;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
import java.awt.event.*;
import java.sql.*;
import java.util.Date;
public class FastCash extends JFrame implements ActionListener {
JButton deposit, withdrawl, ministatement, pinchange, fastcash, balanceenquiry, exit;
String pinnumber;
FastCash(String pinnumber) {
this.pinnumber = pinnumber;
setLayout(null);
URL imageURL = getClass().getResource("/icons/atm.jpg");
if (imageURL == null) {
System.out.println("Error: Image not found at the specified path: /icons/atm.jpg");
}
ImageIcon i1 = new ImageIcon(imageURL);
Image i2 = i1.getImage().getScaledInstance(900, 900, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
JLabel image = new JLabel(i3);
image.setBounds(0, 0, 900, 900);
add(image);
JLabel text = new JLabel("SELECT WITHDRAWL AMOUNT");
text.setBounds(210, 300, 700, 35);
text.setForeground(Color.WHITE);
text.setFont(new Font("System", Font.BOLD, 16));
image.add(text);
deposit = new JButton("Rs 100");
deposit.setBounds(170, 415, 150, 30);
deposit.addActionListener(this);
image.add(deposit);
withdrawl = new JButton("Rs 500");
withdrawl.setBounds(355, 415, 150, 30);
withdrawl.addActionListener(this);
image.add(withdrawl);
fastcash = new JButton("Rs 1000");
fastcash.setBounds(170, 450, 150, 30);
fastcash.addActionListener(this);
image.add(fastcash);
ministatement = new JButton("Rs 2000");
ministatement.setBounds(355, 450, 150, 30);
ministatement.addActionListener(this);
image.add(ministatement);
pinchange = new JButton("Rs 5000");
pinchange.setBounds(170, 485, 150, 30);
pinchange.addActionListener(this);
image.add(pinchange);
balanceenquiry = new JButton("Rs 10000");
balanceenquiry.setBounds(355, 485, 150, 30);
balanceenquiry.addActionListener(this);
image.add(balanceenquiry);
exit = new JButton("Back");
exit.setBounds(355, 520, 150, 30);
exit.addActionListener(this);
image.add(exit);
setSize(900, 900);
setLocation(300, 0);
setUndecorated(true);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == exit) {
setVisible(false);
new Transactions(pinnumber).setVisible(true);
}else{
String amount = ((JButton) ae.getSource()).getText().substring(3);
Conn c = new Conn();
try{
ResultSet rs = c.s.executeQuery("select * from bank where pin = '" + pinnumber + "'");
int balance = 0;
while(rs.next()) {
if (rs.getString("type").equals("Deposit")){
balance += Integer.parseInt(rs.getString("amount"));
}else {
balance -= Integer.parseInt(rs.getString("amount"));
}
}
if (ae.getSource() != exit && balance < Integer.parseInt(amount)) {
JOptionPane.showMessageDialog(null, "Insufficient Balance");
return;
}
Date date = new Date();
String query = "insert into bank values('" + pinnumber + "', '" + date + "', 'Withdrawl', '" + amount + "')";
c.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Rs " + amount + " Debited successfully");
setVisible(false);
new Transactions(pinnumber).setVisible(true);
}catch (Exception e) {
System.out.println(e);
}
}
}
public static void main(String args[]) {
new FastCash("");
}
}