-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeposit.java
More file actions
74 lines (61 loc) · 2.45 KB
/
Copy pathDeposit.java
File metadata and controls
74 lines (61 loc) · 2.45 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Deposit extends JFrame implements ActionListener {
JTextField amountField;
JButton depositButton, backButton;
String cardNumber;
Deposit(String cardNumber) {
this.cardNumber = cardNumber;
setTitle("Deposit");
setLayout(null);
getContentPane().setBackground(Color.white);
JLabel heading = new JLabel("Enter amount to deposit:");
heading.setFont(new Font("Arial", Font.BOLD, 16));
heading.setBounds(60, 40, 250, 30);
add(heading);
amountField = new JTextField();
amountField.setFont(new Font("Arial", Font.PLAIN, 16));
amountField.setBounds(60, 80, 250, 30);
add(amountField);
depositButton = new JButton("Deposit");
depositButton.setBounds(60, 130, 100, 30);
depositButton.addActionListener(this);
add(depositButton);
backButton = new JButton("Back");
backButton.setBounds(210, 130, 100, 30);
backButton.addActionListener(this);
add(backButton);
setSize(400, 250);
setLocation(450, 250);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == depositButton) {
String amount = amountField.getText().trim();
if (amount.isEmpty()) {
JOptionPane.showMessageDialog(null, "Please enter an amount.");
return;
}
try {
Conn conn = new Conn(); // assuming Conn.java has connection setup
String query = "INSERT INTO bank (card_number, date, type, amount) VALUES ('" + cardNumber + "', NOW(), 'Deposit', '" + amount + "')";
conn.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Rs. " + amount + " Deposited Successfully");
setVisible(false);
new Transaction(cardNumber); // ✅ FIXED: pass card number
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Database Error: " + e.getMessage());
}
} else if (ae.getSource() == backButton) {
setVisible(false);
new Transaction(cardNumber); // ✅ FIXED: pass card number
}
}
public static void main(String[] args) {
new Deposit("1234567890123456"); // for testing only
}
}