package com.nameless.bank.frame;

import com.nameless.bank.logic.Account;
import com.nameless.bank.logic.ManagementSystem;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

/**
 * Created by  on 01.04.2016.
 */
public class TransactionDialog extends JDialog implements ActionListener {
    private static final int D_HEIGHT = 150;
    private final static int D_WIDTH = 450;
    private final static int L_X = 10;
    private final static int L_W = 100;
    private final static int C_W = 150;
    private Account accSender;
    private JLabel client = new JLabel();
    private JTextField money = new JTextField();
    private JComboBox<Account> accList;
    public TransactionDialog(Account acc, Vector<Account> accounts){
        accSender=acc;
        int id = acc.getId();
        Vector<Account> accounts1 = new Vector<Account>();
        for(Account a : accounts){
            if(a.getId()!=id){
                accounts1.add(a);
            }
        }
        setTitle(" ");
        getContentPane().setLayout(new FlowLayout());
        getContentPane().setLayout(null);

        JLabel l = new JLabel(":", JLabel.RIGHT);
        l.setBounds(L_X, 10, L_W, 20);
        getContentPane().add(l);
        client.setBounds(L_X + L_W + 10, 10, C_W, 20);
        client.setText(acc.getHolder().getName());
        getContentPane().add(client);

        l = new JLabel(":", JLabel.RIGHT);
        l.setBounds(L_X, 30, L_W, 20);
        getContentPane().add(l);
        accList = new JComboBox(new Vector<Account>(accounts1));
        accList.setBounds(L_X + L_W + 10, 30, C_W, 20);
        getContentPane().add(accList);

        l = new JLabel(":", JLabel.RIGHT);
        l.setBounds(L_X, 50, L_W, 20);
        getContentPane().add(l);
        money.setBounds(L_X + L_W + 10, 50, C_W, 20);
        getContentPane().add(money);

        JButton btnOk = new JButton("OK");
        btnOk.setName("OK");
        btnOk.addActionListener(this);
        btnOk.setBounds(L_X + L_W + C_W + 10 + 50, 10, 100, 25);
        getContentPane().add(btnOk);

        JButton btnCancel = new JButton("Cancel");
        btnCancel.setName("Cancel");
        btnCancel.addActionListener(this);
        btnCancel.setBounds(L_X + L_W + C_W + 10 + 50, 40, 100, 25);
        getContentPane().add(btnCancel);

        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(((int) d.getWidth() - TransactionDialog.D_WIDTH) / 2, ((int) d.getHeight() - TransactionDialog.D_HEIGHT) / 2,
                TransactionDialog.D_WIDTH, TransactionDialog.D_HEIGHT);
    }

    public void actionPerformed(ActionEvent e) {
        JButton src = (JButton) e.getSource();
        if (src.getName().equals("OK")) {
            try {
                if(Integer.parseInt(money.getText())<=accSender.getMoney()){
                    ManagementSystem.getInstance().transact(accSender, (Account) accList.getSelectedItem(), Integer.parseInt(money.getText()));
                }else{
                    JOptionPane.showMessageDialog(TransactionDialog.this,
                            "   ");
                }
            } catch (Exception sql_e) {
                JOptionPane.showMessageDialog(this, sql_e.getMessage());
            }setVisible(false);
        }
        if (src.getName().equals("Cancel")) {
            setVisible(false);
        }
    }
}

@@ -287,16 +287,20 @@
 ated by 
+%D0%93%D0%BB%D0%B5%D0%B1
  on 01.0
@@ -308,16 +308,16 @@
 .2016.%0D%0A
-
  */%0D%0Apub
@@ -1100,17 +1100,35 @@
 tTitle(%22
- 
+%D0%94%D0%BE%D0%B1%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5 %D0%B0%D0%BA%D0%BA%D0%B0%D1%83%D0%BD%D1%82%D0%B0
 %22);%0D%0A   
@@ -1247,32 +1247,43 @@
 l = new JLabel(%22
+%D0%9E%D1%82%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D1%82%D0%B5%D0%BB%D1%8C
 :%22, JLabel.RIGHT
@@ -1525,32 +1525,42 @@
 l = new JLabel(%22
+%D0%9F%D0%BE%D0%BB%D1%83%D1%87%D0%B0%D1%82%D0%B5%D0%BB%D1%8C
 :%22, JLabel.RIGHT
@@ -1826,16 +1826,21 @@
 JLabel(%22
+%D0%A1%D1%83%D0%BC%D0%BC%D0%B0
 :%22, JLab
@@ -3278,19 +3278,45 @@
        %22
-   
+%D0%9D%D0%B5%D0%B4%D0%BE%D1%81%D1%82%D0%B0%D1%82%D0%BE%D1%87%D0%BD%D0%BE %D1%81%D1%80%D0%B5%D0%B4%D1%81%D1%82%D0%B2 %D0%BD%D0%B0 %D1%81%D1%87%D0%B5%D1%82%D0%B5
 %22);%0D%0A   

Update TransactionDialog.java