/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jfrmNuevaCuenta2.java
 *
 * Created on 25-nov-2009, 22:23:21
 */

package bbuvajava;

import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JFrame;

/**
 *
 * @author Administrador
 */
public class jfrmAñadirMasTitular extends javax.swing.JFrame {
    Sucursal AuxSuc;
    CuentaCorriente cuenta;
    ArrayList<Titular> titulares;
    JFrame formularioPPal;
    /** Creates new form jfrmNuevaCuenta2 */
    public jfrmAñadirMasTitular(Sucursal suc, CuentaCorriente p,ArrayList<Titular> t,JFrame form) {
        AuxSuc=suc;
        formularioPPal=form;
        cuenta=p;
        titulares=t;
        String texto="";
        Iterator it=titulares.listIterator();
        initComponents();

        jlblNumCuenta.setText(p.getNumeroCuenta());
      
        while (it.hasNext()){
            Titular ti=(Titular) it.next();
            texto=texto+ti.getNombre()+"\t"+ti.getNumIdent()+"\n";
        }

        jtxaTitulares.setText(texto);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jlblNumCuenta = new javax.swing.JLabel();
        jbtnAñadirTitular = new javax.swing.JButton();
        jbtnFinalizar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxaTitulares = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("PRODUCTOS - CUENTA CORRIENTE - AÑADIR TITULAR");

        jLabel2.setText("Numero de Cuenta: ");

        jbtnAñadirTitular.setText("Añadir Titular");
        jbtnAñadirTitular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAñadirTitularActionPerformed(evt);
            }
        });

        jbtnFinalizar.setText("Finalizar");
        jbtnFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnFinalizarActionPerformed(evt);
            }
        });

        jLabel3.setText("Titulares:");

        jtxaTitulares.setBackground(new java.awt.Color(240, 240, 240));
        jtxaTitulares.setColumns(20);
        jtxaTitulares.setRows(5);
        jScrollPane1.setViewportView(jtxaTitulares);

        jLabel4.setText("Pulse Añadir Titular para añadir más titulares a la cuenta o finalizar para terminar la creación de la Cuenta");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(jlblNumCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(53, 53, 53)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(424, Short.MAX_VALUE)
                .addComponent(jbtnAñadirTitular)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtnFinalizar)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(73, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addGap(38, 38, 38))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jlblNumCuenta))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnFinalizar)
                    .addComponent(jbtnAñadirTitular))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnAñadirTitularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAñadirTitularActionPerformed
        // TODO add your handling code here:
        
        new jfrmAñadirTitular(AuxSuc,cuenta,titulares,formularioPPal).setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jbtnAñadirTitularActionPerformed

    private void jbtnFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnFinalizarActionPerformed
        // TODO add your handling code here:
        cuenta.setTitular(titulares);
        AuxSuc.insertaProductoenSucursal(cuenta);
        formularioPPal.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jbtnFinalizarActionPerformed

    /**
    * @param args the command line arguments
    */
    /*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jfrmNuevaCuenta2().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnAñadirTitular;
    private javax.swing.JButton jbtnFinalizar;
    private javax.swing.JLabel jlblNumCuenta;
    private javax.swing.JTextArea jtxaTitulares;
    // End of variables declaration//GEN-END:variables

}
