Advertisement
Guest User

Untitled

a guest
Jan 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.11 KB | None | 0 0
  1. package me.Bank;
  2.  
  3. import javax.swing.*;
  4. import javax.swing.plaf.basic.BasicSplitPaneUI;
  5. import java.awt.*;
  6. import java.awt.event.KeyEvent;
  7. import java.awt.event.KeyListener;
  8.  
  9. public class CreateAccountWindow extends JFrame implements KeyListener {
  10.     JTextField name;
  11.     JTextField initialBalance;
  12.  
  13.     JRadioButton budgetAccount;
  14.     JRadioButton savingsAccount;
  15.     ButtonGroup accountType;
  16.  
  17.     JPanel textFieldsPane;
  18.     JPanel radioButtonsPane;
  19.  
  20.     User currentUser;
  21.  
  22.     public CreateAccountWindow(User currentUser) {
  23.         this.currentUser = currentUser;
  24.         textFieldsPane = new JPanel();
  25.         radioButtonsPane = new JPanel();
  26.  
  27.         createTextFields();
  28.         createRadioButtons();
  29.         this.getContentPane().add(textFieldsPane, BorderLayout.NORTH);
  30.         this.getContentPane().add(radioButtonsPane, BorderLayout.SOUTH);
  31.     }
  32.  
  33.     public void createTextFields() {
  34.         name = new JTextField("Nazwa Konta");
  35.         initialBalance = new JTextField("0.0");
  36.         textFieldsPane.add(name);
  37.         textFieldsPane.add(initialBalance);
  38.     }
  39.  
  40.     public void createRadioButtons() {
  41.         accountType = new ButtonGroup();
  42.         budgetAccount = new JRadioButton("Budget Account", true);
  43.         savingsAccount = new JRadioButton("Savings Account", false);
  44.         accountType.add(budgetAccount);
  45.         accountType.add(savingsAccount);
  46.         radioButtonsPane.add(budgetAccount);
  47.         radioButtonsPane.add(savingsAccount);
  48.     }
  49.  
  50.     @Override
  51.     public void keyTyped(KeyEvent e) {
  52.         if (e.getKeyCode() == KeyEvent.VK_ENTER) {
  53.             createAccount();
  54.             this.dispose();
  55.         }
  56.     }
  57.  
  58.     @Override
  59.     public void keyPressed(KeyEvent e) {
  60.         if (e.getKeyCode() == KeyEvent.VK_ENTER) {
  61.             createAccount();
  62.             this.dispose();
  63.         }
  64.     }
  65.  
  66.     @Override
  67.     public void keyReleased(KeyEvent e) {
  68.  
  69.     }
  70.  
  71.     private void createAccount() {
  72.         currentUser.getAccounts().add(new Account(currentUser.getLogin(), name.getText(),
  73.                 Float.parseFloat(initialBalance.getText()) ));
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement