depositjava project
depositjava project
management;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
Deposit(String pin) {
this.pin = pin;
// Deposit button
b1 = new JButton("DEPOSIT");
b1.setBounds(700, 362, 150, 35);
b1.setBackground(new Color(65, 125, 128));
b1.setForeground(Color.WHITE);
b1.addActionListener(this);
image.add(b1);
// Back button
b2 = new JButton("BACK");
b2.setBounds(700, 406, 150, 35);
b2.setBackground(new Color(65, 125, 128));
b2.setForeground(Color.WHITE);
b2.addActionListener(this);
image.add(b2);
setLayout(null);
setSize(1550, 1080);
setLocation(0, 0);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
try {
String amount = textfield.getText();
Date date = new Date();
if (e.getSource() == b1) {
if (textfield.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Please enter the amount you want to
deposit");
} else {
Con c = new Con();
// Fixed SQL syntax error: Corrected the query string
String query = "INSERT INTO bank (pin, date, type, amount) VALUES ('" + pin + "',
'" + date + "', 'Deposit', '" + amount + "')";
c.stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Rs. " + amount + " deposited
successfully");
setVisible(false);
}
} else if (e.getSource() == b2) {
setVisible(false);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}