Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.Bank;
- import javax.swing.*;
- import javax.swing.plaf.basic.BasicSplitPaneUI;
- import java.awt.*;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- public class CreateAccountWindow extends JFrame implements KeyListener {
- JTextField name;
- JTextField initialBalance;
- JRadioButton budgetAccount;
- JRadioButton savingsAccount;
- ButtonGroup accountType;
- JPanel textFieldsPane;
- JPanel radioButtonsPane;
- User currentUser;
- public CreateAccountWindow(User currentUser) {
- this.currentUser = currentUser;
- textFieldsPane = new JPanel();
- radioButtonsPane = new JPanel();
- createTextFields();
- createRadioButtons();
- this.getContentPane().add(textFieldsPane, BorderLayout.NORTH);
- this.getContentPane().add(radioButtonsPane, BorderLayout.SOUTH);
- }
- public void createTextFields() {
- name = new JTextField("Nazwa Konta");
- initialBalance = new JTextField("0.0");
- textFieldsPane.add(name);
- textFieldsPane.add(initialBalance);
- }
- public void createRadioButtons() {
- accountType = new ButtonGroup();
- budgetAccount = new JRadioButton("Budget Account", true);
- savingsAccount = new JRadioButton("Savings Account", false);
- accountType.add(budgetAccount);
- accountType.add(savingsAccount);
- radioButtonsPane.add(budgetAccount);
- radioButtonsPane.add(savingsAccount);
- }
- @Override
- public void keyTyped(KeyEvent e) {
- if (e.getKeyCode() == KeyEvent.VK_ENTER) {
- createAccount();
- this.dispose();
- }
- }
- @Override
- public void keyPressed(KeyEvent e) {
- if (e.getKeyCode() == KeyEvent.VK_ENTER) {
- createAccount();
- this.dispose();
- }
- }
- @Override
- public void keyReleased(KeyEvent e) {
- }
- private void createAccount() {
- currentUser.getAccounts().add(new Account(currentUser.getLogin(), name.getText(),
- Float.parseFloat(initialBalance.getText()) ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement