Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.HashMap;
- public class BankingSystem {
- private static HashMap<String, Double> accounts = new HashMap<>();
- public static void main(String[] args) {
- JFrame frame = new JFrame("Banking System");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(800, 600);
- JPanel panel = new JPanel();
- frame.add(panel);
- placeComponents(panel);
- frame.setVisible(true);
- }
- private static void placeComponents(JPanel panel) {
- panel.setLayout(null);
- JLabel accountLabel = new JLabel("Счет:");
- accountLabel.setBounds(10, 20, 80, 25);
- panel.add(accountLabel);
- JTextField accountText = new JTextField(20);
- accountText.setBounds(100, 20, 250, 25);
- panel.add(accountText);
- JLabel amountLabel = new JLabel("Сумма:");
- amountLabel.setBounds(10, 50, 80, 25);
- panel.add(amountLabel);
- JTextField amountText = new JTextField(20);
- amountText.setBounds(100, 50, 250, 25);
- panel.add(amountText);
- JButton openButton = new JButton("Открыть счет");
- openButton.setBounds(10, 80, 200, 25);
- openButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String account = accountText.getText();
- accounts.put(account, 0.0);
- JOptionPane.showMessageDialog(null, "Счет открыт");
- }
- });
- panel.add(openButton);
- JButton depositButton = new JButton("Внесение средств");
- depositButton.setBounds(210, 80, 200, 25);
- depositButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String account = accountText.getText();
- double amount = Double.parseDouble(amountText.getText());
- if (accounts.containsKey(account)) {
- double balance = accounts.get(account);
- accounts.put(account, balance + amount);
- JOptionPane.showMessageDialog(null, "Деньги успешно внесены");
- } else {
- JOptionPane.showMessageDialog(null, "Счета не существует");
- }
- }
- });
- panel.add(depositButton);
- JButton withdrawButton = new JButton("Снятие средств");
- withdrawButton.setBounds(400, 80, 200, 25);
- withdrawButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String account = accountText.getText();
- double amount = Double.parseDouble(amountText.getText());
- if (accounts.containsKey(account)) {
- double balance = accounts.get(account);
- if (balance >= amount) {
- accounts.put(account, balance - amount);
- JOptionPane.showMessageDialog(null, "Деньги успешно сняты");
- } else {
- JOptionPane.showMessageDialog(null, "Не хватает средств");
- }
- } else {
- JOptionPane.showMessageDialog(null, "Счета не существует");
- }
- }
- });
- panel.add(withdrawButton);
- JButton balanceButton = new JButton("Баланас");
- balanceButton.setBounds(600, 80, 100, 25);
- balanceButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String account = accountText.getText();
- if (accounts.containsKey(account)) {
- double balance = accounts.get(account);
- JOptionPane.showMessageDialog(null, "Ваш текущий баланс: " + balance);
- } else {
- JOptionPane.showMessageDialog(null, "Счета не существует");
- }
- }
- });
- panel.add(balanceButton);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement