package formulario4;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Formulario04 extends JFrame{
Container cn;
FlowLayout gy;
JPanel p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p41;
JButton bt1,bt2;
public Formulario04(String Formulario04)
{
super(Formulario04);
setSize(new Dimension(400,400));
cn = getContentPane();
// AÑADIR LAYOUT AL CONTENEDOR
gy = new FlowLayout(FlowLayout.CENTER);
cn.setLayout(gy);
// CONSTRUCCION DE PANELES
p1 = new JPanel(gy);
p1.setBackground(Color.WHITE);
JLabel lb1 = new JLabel("NOMBRE");
lb1.setForeground(Color.BLACK);
JTextField tx1 = new JTextField("",15);
tx1.setForeground(Color.BLACK);
p1.add(lb1);
p1.add(tx1);
p2 = new JPanel(gy);
p2.setBackground(Color.WHITE);
JLabel lb2 = new JLabel("APELLIDO");
lb2.setForeground(Color.BLACK);
JTextField tx2 = new JTextField("",15);
tx2.setForeground(Color.BLACK);
p2.add(lb2);
p2.add(tx2);
p3 = new JPanel(gy);
p3.setBackground(Color.WHITE);
JLabel lb3 = new JLabel("EDAD");
lb3.setForeground(Color.BLACK);
JTextField tx3 = new JTextField("",15);
tx3.setForeground(Color.BLACK);
p3.add(lb3);
p3.add(tx3);
p4 = new JPanel(gy);
p4.setBackground(Color.WHITE);
JLabel lb4 = new JLabel("TIPO DE DOCUMENTO");
lb4.setForeground(Color.BLACK);
JTextField tx4 = new JTextField("",15);
tx1.setForeground(Color.BLACK);
p4.add(lb4);
p4.add(tx4);
p5 = new JPanel(gy);
p5.setBackground(Color.WHITE);
JLabel lb5 = new JLabel("NUMERO DE DOCUMENTO");
lb5.setForeground(Color.BLACK);
JTextField tx5 = new JTextField("",15);
tx1.setForeground(Color.BLACK);
p5.add(lb5);
p5.add(tx5);
p6 = new JPanel(gy);
p6.setBackground(Color.WHITE);
JLabel lb6 = new JLabel("DIRECCION");
lb6.setForeground(Color.BLACK);
JTextField tx6 = new JTextField("",15);
tx6.setForeground(Color.BLACK);
p6.add(lb6);
p6.add(tx6);
p7 = new JPanel(gy);
p7.setBackground(Color.WHITE);
JLabel lb7 = new JLabel("TELEFONO");
lb7.setForeground(Color.BLACK);
JTextField tx7 = new JTextField("",15);
tx7.setForeground(Color.BLACK);
p7.add(lb7);
p7.add(tx7);
p8 = new JPanel(gy);
p8.setBackground(Color.WHITE);
JLabel lb8 = new JLabel("FECHA DE NACIMIENTO");
lb8.setForeground(Color.BLACK);
JTextField tx8 = new JTextField("",15);
tx8.setForeground(Color.BLACK);
p8.add(lb8);
p8.add(tx8);
p9 = new JPanel(gy);
p9.setBackground(Color.WHITE);
JLabel lb9 = new JLabel("LUGAR DE NACIMENTO");
lb9.setForeground(Color.BLACK);
JTextField tx9 = new JTextField("",15);
tx9.setForeground(Color.BLACK);
p9.add(lb9);
p9.add(tx9);
p10 = new JPanel(gy);
p10.setBackground(Color.WHITE);
JLabel lb10 = new JLabel("TIPO DE SANGRE");
lb10.setForeground(Color.BLACK);
JTextField tx10 = new JTextField("",15);
tx10.setForeground(Color.BLACK);
p10.add(lb10);
p10.add(tx10);
p11 = new JPanel(gy);
p11.setBackground(Color.WHITE);
JLabel lb11 = new JLabel("MUSICA FAVORITA");
lb11.setForeground(Color.BLACK);
JTextField tx11 = new JTextField("",15);
tx11.setForeground(Color.BLACK);
p11.add(lb11);
p11.add(tx11);
p12 = new JPanel(gy);
p12.setBackground(Color.WHITE);
JLabel lb12 = new JLabel("NOMBRE DEL PADRE");
lb12.setForeground(Color.BLACK);
JTextField tx12 = new JTextField("",15);
tx12.setForeground(Color.BLACK);
p12.add(lb12);
p12.add(tx12);
p13 = new JPanel(gy);
p13.setBackground(Color.WHITE);
JLabel lb13 = new JLabel("NOMBRE DE LA MADRE");
lb13.setForeground(Color.BLACK);
JTextField tx13 = new JTextField("",15);
tx13.setForeground(Color.BLACK);
p13.add(lb13);
p13.add(tx13);
bt1= new JButton ("Aceptar");
bt2= new JButton ("Cancelar");
// AÑADIR PANELES
cn.add(p1);
cn.add(p2);
cn.add(p3);
cn.add(p4);
cn.add(p5);
cn.add(p6);
cn.add(p7);
cn.add(p8);
cn.add(p9);
cn.add(p10);
cn.add(p11);
cn.add(p12);
cn.add(p13);
// LECTURA DE DATOS INTRODUCIDOS
String texto =tx1.getText(); // TEXTO INICIAL
tx1.addActionListener(new Lector1());
tx2.addActionListener(new Lector2());
tx3.addActionListener(new Lector3());
tx4.addActionListener(new Lector4());
tx5.addActionListener(new Lector5());
tx6.addActionListener(new Lector6());
tx7.addActionListener(new Lector7());
tx8.addActionListener(new Lector8());
tx9.addActionListener(new Lector9());
tx10.addActionListener(new Lector10());
tx11.addActionListener(new Lector11());
tx12.addActionListener(new Lector12());
tx13.addActionListener(new Lector13());
// FINAL: CIERRE DE VENTANA
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println("ADIOStexto");
}
public static void main(String[] args)
{
Formulario04 frame = new Formulario04(" Formulario04 ");
frame.setVisible(true);
}
// LEE CUANDO SE PRESIONE RETURN EN EL CAMPO CORRESPONDIENTE
class Lector1 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("NOMBRE" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector2 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println ("APELLIDO" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector3 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println ("EDAD" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector4 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println ("TIPO DE DOCUMENTO" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector5 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println ("NUMERO DE DOCUMENTO" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector6 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println ("DIRECCION" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector7 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println ("TELEFONO" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector8 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("FECHA DE NACIMIENTO" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector9 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("LUGAR DE NACIMIENTO" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector10 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("TIPO DE SANGRE" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector11 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("MUSICA FAVORITA" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector12 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("NOMBRE DEL PADRE " + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector13 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("NOMBRE DE LA MADRE" + ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
}

Formulario4

  • 1.
    package formulario4; import java.awt.Color; importjava.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class Formulario04 extends JFrame{ Container cn; FlowLayout gy; JPanel p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p41; JButton bt1,bt2; public Formulario04(String Formulario04) { super(Formulario04); setSize(new Dimension(400,400)); cn = getContentPane(); // AÑADIR LAYOUT AL CONTENEDOR gy = new FlowLayout(FlowLayout.CENTER); cn.setLayout(gy); // CONSTRUCCION DE PANELES p1 = new JPanel(gy); p1.setBackground(Color.WHITE); JLabel lb1 = new JLabel("NOMBRE"); lb1.setForeground(Color.BLACK); JTextField tx1 = new JTextField("",15); tx1.setForeground(Color.BLACK); p1.add(lb1);
  • 2.
    p1.add(tx1); p2 = newJPanel(gy); p2.setBackground(Color.WHITE); JLabel lb2 = new JLabel("APELLIDO"); lb2.setForeground(Color.BLACK); JTextField tx2 = new JTextField("",15); tx2.setForeground(Color.BLACK); p2.add(lb2); p2.add(tx2); p3 = new JPanel(gy); p3.setBackground(Color.WHITE); JLabel lb3 = new JLabel("EDAD"); lb3.setForeground(Color.BLACK); JTextField tx3 = new JTextField("",15); tx3.setForeground(Color.BLACK); p3.add(lb3); p3.add(tx3); p4 = new JPanel(gy); p4.setBackground(Color.WHITE); JLabel lb4 = new JLabel("TIPO DE DOCUMENTO"); lb4.setForeground(Color.BLACK); JTextField tx4 = new JTextField("",15); tx1.setForeground(Color.BLACK); p4.add(lb4); p4.add(tx4); p5 = new JPanel(gy); p5.setBackground(Color.WHITE); JLabel lb5 = new JLabel("NUMERO DE DOCUMENTO"); lb5.setForeground(Color.BLACK); JTextField tx5 = new JTextField("",15); tx1.setForeground(Color.BLACK); p5.add(lb5); p5.add(tx5); p6 = new JPanel(gy); p6.setBackground(Color.WHITE); JLabel lb6 = new JLabel("DIRECCION");
  • 3.
    lb6.setForeground(Color.BLACK); JTextField tx6 =new JTextField("",15); tx6.setForeground(Color.BLACK); p6.add(lb6); p6.add(tx6); p7 = new JPanel(gy); p7.setBackground(Color.WHITE); JLabel lb7 = new JLabel("TELEFONO"); lb7.setForeground(Color.BLACK); JTextField tx7 = new JTextField("",15); tx7.setForeground(Color.BLACK); p7.add(lb7); p7.add(tx7); p8 = new JPanel(gy); p8.setBackground(Color.WHITE); JLabel lb8 = new JLabel("FECHA DE NACIMIENTO"); lb8.setForeground(Color.BLACK); JTextField tx8 = new JTextField("",15); tx8.setForeground(Color.BLACK); p8.add(lb8); p8.add(tx8); p9 = new JPanel(gy); p9.setBackground(Color.WHITE); JLabel lb9 = new JLabel("LUGAR DE NACIMENTO"); lb9.setForeground(Color.BLACK); JTextField tx9 = new JTextField("",15); tx9.setForeground(Color.BLACK); p9.add(lb9); p9.add(tx9); p10 = new JPanel(gy); p10.setBackground(Color.WHITE); JLabel lb10 = new JLabel("TIPO DE SANGRE"); lb10.setForeground(Color.BLACK); JTextField tx10 = new JTextField("",15); tx10.setForeground(Color.BLACK); p10.add(lb10); p10.add(tx10); p11 = new JPanel(gy);
  • 4.
    p11.setBackground(Color.WHITE); JLabel lb11 =new JLabel("MUSICA FAVORITA"); lb11.setForeground(Color.BLACK); JTextField tx11 = new JTextField("",15); tx11.setForeground(Color.BLACK); p11.add(lb11); p11.add(tx11); p12 = new JPanel(gy); p12.setBackground(Color.WHITE); JLabel lb12 = new JLabel("NOMBRE DEL PADRE"); lb12.setForeground(Color.BLACK); JTextField tx12 = new JTextField("",15); tx12.setForeground(Color.BLACK); p12.add(lb12); p12.add(tx12); p13 = new JPanel(gy); p13.setBackground(Color.WHITE); JLabel lb13 = new JLabel("NOMBRE DE LA MADRE"); lb13.setForeground(Color.BLACK); JTextField tx13 = new JTextField("",15); tx13.setForeground(Color.BLACK); p13.add(lb13); p13.add(tx13); bt1= new JButton ("Aceptar"); bt2= new JButton ("Cancelar"); // AÑADIR PANELES cn.add(p1); cn.add(p2); cn.add(p3); cn.add(p4); cn.add(p5); cn.add(p6); cn.add(p7); cn.add(p8); cn.add(p9); cn.add(p10); cn.add(p11); cn.add(p12);
  • 5.
    cn.add(p13); // LECTURA DEDATOS INTRODUCIDOS String texto =tx1.getText(); // TEXTO INICIAL tx1.addActionListener(new Lector1()); tx2.addActionListener(new Lector2()); tx3.addActionListener(new Lector3()); tx4.addActionListener(new Lector4()); tx5.addActionListener(new Lector5()); tx6.addActionListener(new Lector6()); tx7.addActionListener(new Lector7()); tx8.addActionListener(new Lector8()); tx9.addActionListener(new Lector9()); tx10.addActionListener(new Lector10()); tx11.addActionListener(new Lector11()); tx12.addActionListener(new Lector12()); tx13.addActionListener(new Lector13()); // FINAL: CIERRE DE VENTANA setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); System.out.println("ADIOStexto"); } public static void main(String[] args) { Formulario04 frame = new Formulario04(" Formulario04 "); frame.setVisible(true); } // LEE CUANDO SE PRESIONE RETURN EN EL CAMPO CORRESPONDIENTE class Lector1 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.print("NOMBRE" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector2 implements ActionListener
  • 6.
    { private int i; @Override publicvoid actionPerformed(ActionEvent e) { System.out.println ("APELLIDO" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector3 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.println ("EDAD" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector4 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.println ("TIPO DE DOCUMENTO" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector5 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.println ("NUMERO DE DOCUMENTO" + ": ");
  • 7.
    System.out.println(((JTextField)e.getSource()).getText()); } } class Lector6 implementsActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.println ("DIRECCION" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector7 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.println ("TELEFONO" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector8 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.print("FECHA DE NACIMIENTO" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector9 implements ActionListener {
  • 8.
    private int i; @Override publicvoid actionPerformed(ActionEvent e) { System.out.print("LUGAR DE NACIMIENTO" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector10 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.print("TIPO DE SANGRE" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector11 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.print("MUSICA FAVORITA" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } class Lector12 implements ActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.print("NOMBRE DEL PADRE " + ": ");
  • 9.
    System.out.println(((JTextField)e.getSource()).getText()); } } class Lector13 implementsActionListener { private int i; @Override public void actionPerformed(ActionEvent e) { System.out.print("NOMBRE DE LA MADRE" + ": "); System.out.println(((JTextField)e.getSource()).getText()); } } }