-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBankManagerGUI.java
More file actions
140 lines (118 loc) · 5.19 KB
/
BankManagerGUI.java
File metadata and controls
140 lines (118 loc) · 5.19 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
140
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class BankManagerGUI {
private JFrame frame;
private JTextField txtAccountId;
private JTextField txtAmount;
private BankManager bankManager;
public BankManagerGUI(BankManager bankManager) {
this.bankManager = bankManager;
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create the title label
JLabel lblTitle = new JLabel("Gestion Bancaire", SwingConstants.CENTER);
lblTitle.setFont(new Font("Serif", Font.BOLD, 20)); // Set font size and style as needed
// Other components
JLabel lblAccountId = new JLabel("Compte ID:");
txtAccountId = new JTextField();
txtAccountId.setColumns(10);
JLabel lblAmount = new JLabel("Somme:");
txtAmount = new JTextField();
txtAmount.setColumns(10);
JButton btnCreateAccount = new JButton("Creer Compte");
btnCreateAccount.addActionListener(this::createAccount);
JButton btnDeposit = new JButton("Ajouter");
btnDeposit.addActionListener(this::deposit);
JButton btnWithdraw = new JButton("Retirer");
btnWithdraw.addActionListener(this::withdraw);
JButton btnTransfer = new JButton("Transferer");
btnTransfer.addActionListener(this::transfer);
JButton btnCheckBalance = new JButton("Consulter Solde");
btnCheckBalance.addActionListener(this::checkBalance);
// Layout for the title
JPanel titlePanel = new JPanel(new BorderLayout());
titlePanel.add(lblTitle, BorderLayout.CENTER);
// Layout for the main components
JPanel mainPanel = new JPanel(new GridLayout(0, 2, 10, 10));
mainPanel.add(lblAccountId);
mainPanel.add(txtAccountId);
mainPanel.add(lblAmount);
mainPanel.add(txtAmount);
mainPanel.add(btnCreateAccount);
mainPanel.add(btnDeposit);
mainPanel.add(btnWithdraw);
mainPanel.add(btnTransfer);
mainPanel.add(btnCheckBalance);
// Add title panel at the top and main panel at the center
frame.setLayout(new BorderLayout());
frame.add(titlePanel, BorderLayout.NORTH);
frame.add(mainPanel, BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void createAccount(ActionEvent e) {
try {
String id = txtAccountId.getText();
double amount = Double.parseDouble(txtAmount.getText());
bankManager.creerCompte(id, amount);
JOptionPane.showMessageDialog(frame, "Compte créé avec succès !");
} catch (Exception ex) {
JOptionPane.showMessageDialog(frame, "Erreur: " + ex.getMessage());
}
}
private void deposit(ActionEvent e) {
try {
String id = txtAccountId.getText();
double amount = Double.parseDouble(txtAmount.getText());
bankManager.ajouter(id, amount);
JOptionPane.showMessageDialog(frame, "Montant déposé avec succès !");
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Veuillez entrer un nombre valide pour le montant.");
} catch (Exception ex) {
JOptionPane.showMessageDialog(frame, "Erreur: " + ex.getMessage());
}
}
private void withdraw(ActionEvent e) {
try {
String id = txtAccountId.getText();
double amount = Double.parseDouble(txtAmount.getText());
bankManager.retirer(id, amount);
JOptionPane.showMessageDialog(frame, "Montant retiré avec succès !");
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Veuillez entrer un nombre valide pour le montant.");
} catch (Exception ex) {
JOptionPane.showMessageDialog(frame, "Erreur: " + ex.getMessage());
}
}
private void transfer(ActionEvent e) {
String id_C = JOptionPane.showInputDialog(frame, "Entrez l'identifiant du compte source :");
String id_D = JOptionPane.showInputDialog(frame, "Entrez l'identifiant du compte de destination:");
try {
double amount = Double.parseDouble(txtAmount.getText());
bankManager.transfererSolde(id_C, id_D, amount);
JOptionPane.showMessageDialog(frame, "Montant transféré avec succès !");
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Veuillez entrer un montant valide.");
} catch (Exception ex) {
JOptionPane.showMessageDialog(frame, "Erreur: " + ex.getMessage());
}
}
private void checkBalance(ActionEvent e) {
try {
String id = txtAccountId.getText();
double balance = bankManager.consulterSolde(id);
JOptionPane.showMessageDialog(frame, "Solde: " + balance);
} catch (Exception ex) {
JOptionPane.showMessageDialog(frame, "Erreur: " + ex.getMessage());
}
}
public JFrame getFrame() {
return frame;
}
}