Sei sulla pagina 1di 10

package capturarPersonaV3;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import ejGUI.B_SegundaInterfase;

public class CapturarPersonaV3 extends JFrame implements ActionListener


{

private JLabel memNombre, memApellido , memEdad , memSexo, memEstado , memCedula,memVacio;


private JButton botAceptar, botCancelar, botSalir;
private JTextField strNombre, strApellido , strEdad ,strCedula ;
private JRadioButton rabFemenino, rabMasculino;
int intEdad=0, intCedula=0,intUltDig=0,intTotalDig=0;
String strNombre1="",strApellido1="", strEdad1="",strCedula1="" ;
private String opciones[]={"","Soltero","Casado","Viudo","Divorciado","Unido"};
private JComboBox comboOpciones;
private boolean boolCorrecto1=false, boolCorrecto=false, boolEdad=false,boolCed=false;
private JTextArea jtaImpri;

public CapturarPersonaV3 ()
{

super ("CAPTURAR PERSONA V3");


JPanel docGui=new JPanel();
docGui.setLayout(new GridLayout(9,2,5,10));
//asignacion a los JLabel un string

memNombre= new JLabel (" NOMBRE");


memApellido =new JLabel (" APELLIDO");
memEdad=new JLabel (" EDAD");
memSexo=new JLabel (" SEXO");
memEstado =new JLabel (" ESTADO CIVIL");
memCedula =new JLabel (" CEDULA");
memVacio=new JLabel ("");

//Asignacion a los jButton un string


botAceptar=new JButton();
botAceptar.setText("ACEPTAR");
botAceptar.setActionCommand("ACEPTAR");
botAceptar.addActionListener(this);
botCancelar=new JButton();
botCancelar.setText("CANCELAR");
botCancelar.setActionCommand("CANCELAR");
botCancelar.addActionListener(this);
botSalir=new JButton();
botSalir.setText("SALIR");
botSalir.setActionCommand("SALIR");
botSalir.addActionListener(this);

//Asignacion a los JTextField u n string


strNombre=new JTextField();
strApellido=new JTextField();
strEdad=new JTextField();
strCedula=new JTextField();

//Asignacion de los JRadioButton a un string


rabFemenino = new JRadioButton();
rabFemenino.setText("FEMENINO");
rabMasculino=new JRadioButton();
rabMasculino.setText("Masculino");

//asigancion a los JComboBox un string


comboOpciones= new JComboBox(opciones);
comboOpciones.setMaximumRowCount(6);

//impresion en el panel de texto


docGui.add(memNombre);
docGui.add(strNombre);
docGui.add(memApellido);
docGui.add(strApellido);
docGui.add(memEdad);
docGui.add(strEdad);
docGui.add(memSexo);
docGui.add(memVacio);
docGui.add(rabFemenino);
docGui.add(rabMasculino);
docGui.add(memEstado);
docGui.add(comboOpciones);
docGui.add(memCedula);
docGui.add(strCedula);
docGui.add(botAceptar);
docGui.add(botCancelar);
docGui.add(botSalir);

//CONTENEDOR
Container contenedor = getContentPane();
contenedor.setBackground(Color.lightGray);
contenedor.add(new JLabel("CapturarPersonaV3",new
ImageIcon("imagenes/proveedor.png"),SwingConstants.CENTER),BorderLayout.NORTH);
contenedor.add(docGui,BorderLayout.CENTER);
super.setBounds(100, 200, 400, 150);
this.setVisible(true);

}
public static void main( String args[] )
{
CapturarPersonaV3 application = new CapturarPersonaV3();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

}
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
String a = e.getActionCommand();
if(a.equals("ACEPTAR"))
{
Verificacion();
}

if(a.equals("CANCELAR"))
{
Limpiar();

if(a.equals("SALIR"))
{
Limpiar();
System.exit(0);
}
}
public void Verificacion()
{
String strTotal="";
strNombre1=String.valueOf(strNombre.getText());
strApellido1=String.valueOf(strApellido.getText());
strEdad1=String.valueOf(strEdad.getText());
strCedula1=String.valueOf(strCedula.getText());
//REALIZA LA ACCION DE OBTENER EL NOMBRE Y COMPARAR CADA UNO DE SUS
CARACTERES CON LO QUE SE SOLICITA AL USUARIO
if((this.strNombre1.length()<10)){//COMPARAMOS QUE SEA MENOR A 10 CARACTERES
boolCorrecto1= this.strNombre1.matches("([a-z A-Z
])+");//ESPECIFICAMOS TIPOS DE CARACTERES A INGRESAR
if(boolCorrecto1==false){
RESULTO CON LO QUE SOLICITABA NOS DEVUELVE UN MENSAJE

//SI LA TAREA ANTERIOR NO

strTotal="NOMBRE INCORRECTO SOLO LETRAS POR FAVOR, ";


}
else{
boolCorrecto1=true;//SI LO SOLICITADO ES CORRECTO SE PASA AL
SIGUIENTE PASO
}
}
else{

strTotal=" NOMBRE MAXIMO 10 CARACTERES ALFABETICOS, "+strTotal;//SI LO


INGRESADO EXCEDE EL NUMERO DE CARACTERES SE RETORNA UN MENSAJE DE ADVERTENCIA Y SE VUELVE A
PREGUNTAR
}
if((this.strApellido1.length()<10)){
boolCorrecto= this.strApellido1.matches("([a-z A-Z ])+");
if(boolCorrecto==false){
strTotal="APELLIDO SOLO LETRAS POR FAVOR, "+strTotal;
}
else{
boolCorrecto=true;
}
}
else{
strTotal=" APELLIDO MAXIMO 10 LETRAS, " +strTotal;
}
if(this.strEdad1.length()<4){
boolEdad = this.strEdad1.matches("[0-9]+");
boolEdad = true;
try{
this.intEdad = Integer.parseInt(this.strEdad1);
if(this.intEdad>=0 && this.intEdad <= 125){
boolEdad=true;
}
else{
strTotal="EXCEDE EL RANGO DE EDADES, "+strTotal;
boolEdad=false;
}
}

catch(Exception e){
strTotal="EDAD SOLAMENTE CARACTERES NUMERICOS, "+strTotal;
boolEdad=false;
}
}
else{
strTotal="EDAD NO PERMITIDA, "+strTotal;//DAMOS UN MENSAJE DE
ADVERTENCIA
}
boolCed=true;
try{
if ((this.strCedula1).matches("([a-z]|[A-Z]|\\s)+")) { //PEDIMOS LAS
CARACTERISTICAS QUE DEBE TENER EL DATO Y COMPARAMOS
strTotal="INGRESE CEDULA CORRECTA, "+strTotal; //DAMOS UN
MENSAJE DE ERROR
boolCed=false;
}
else{
if((this.strCedula1.length()==10)){//COMPARAMOS QUE SE
INTROCUSCAN SOLO 10 DIGITOS NO MAS NI MENOS

this.intCedula=Integer.parseInt(this.strCedula1);//TRANSFORMAMOS DE STRING A INT


this.intUltDig=veriCed(this.strCedula1);
this.intTotalDig=Integer.parseInt(this.strCedula1.substring(9));
if(intUltDig==intTotalDig)
{
boolCed=true;
}
else
{

strTotal="CEDULA INVALIDA, "+strTotal; //DAMOS UN


MENSAJE DE ERROR
boolCed=false;
}
}
else{
strTotal="LA CEDULA DEBE CONTENER 10 DIGITOS,
"+strTotal;//MUESTRA MENSAJE DE ERROR
boolCed=false;
}

}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "\n\nVERIFIQUE QUE LOS DATOS SEAN
CORRECTOS" , "Mensaje de error al digitar", JOptionPane.ERROR_MESSAGE);//MENSAJE DE ERROR
boolCed=false;
}
if(boolCorrecto1==false|boolCorrecto==false|boolEdad==false|boolCed==false)
{
JOptionPane.showMessageDialog(null, strTotal , "Mensaje de error al digitar",
JOptionPane.ERROR_MESSAGE);//MENSAJE DE LOS ERRORES TOTALES
}
else
{
impriArea();
Limpiar();
}

public void Limpiar()


{
strNombre.setText("");
strApellido.setText("");
strCedula.setText("");
strEdad.setText("");
}
public int veriCed(String strVeri)
{
int intVeri=0;
int intX=0;
int intY=0;
int suma=0;
int suma1=0;
for(int i=0;i<9;i++)
{
if(i%2==0)
{
intVeri= Integer.parseInt(strVeri.substring(i,i+1));
intX=2*intVeri;
if(intX>=10)
{
intX=intX-9;
}
suma1=suma1+intX;
}
else
{

intY=Integer.parseInt(strVeri.substring(i,i+1));
suma=suma+intY;
}
}
return(10-((suma+suma1)%10));
}
public void impriArea()
{
System.out.println("NOMBRE" +strNombre1);
jtaImpri.append("Nombre: ");
}
}

Potrebbero piacerti anche