1. package cuestionario;
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.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
/*
* @author RLR
*/
public class Cuestionario extends JFrame{
Container cn;
FlowLayout gy;
JPanel
p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,
p24,p25,p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36,p37,p38,p39,p40;
public Cuestionario(String nameFormulario)
{
super(nameFormulario);
setSize(new Dimension(300,300));
cn = getContentPane();
// AÑADIR LAYOUT AL CONTENEDOR
gy = new FlowLayout(FlowLayout.CENTER);
cn.setLayout(gy);
JFrame jf = new JFrame("Botones con Java");//creacion de ventana con el titulo
jf.setLayout(new FlowLayout());//Configurar como se dispondra el espacio del jframe
Dimension d = new Dimension();
// CONSTRUCCION DE PANELES
p1 = new JPanel(gy);
2. p1.setBackground(Color.MAGENTA);
JLabel lb1 = new JLabel("NOMBRE");
lb1.setForeground(Color.blue);
JTextField tx1 = new JTextField("",15);
tx1.setForeground(Color.BLACK);
p1.add(lb1);
p1.add(tx1);
p2 = new JPanel(gy);
p2.setBackground(Color.MAGENTA);
JLabel lb2 = new JLabel("APELLIDOS");
lb2.setForeground(Color.blue);
JTextField tx2 = new JTextField("",15);
tx2.setForeground(Color.BLACK);
p2.add(lb2);
p2.add(tx2);
p3 = new JPanel(gy);
p3.setBackground(Color.MAGENTA);
JLabel lb3 = new JLabel("DOCUMENTO");
lb3.setForeground(Color.blue);
JTextField tx3 = new JTextField("",15);
tx3.setForeground(Color.BLACK);
p3.add(lb3);
p3.add(tx3);
p4 = new JPanel(gy);
p4.setBackground(Color.MAGENTA);
JLabel lb4 = new JLabel("TELEFONO");
lb4.setForeground(Color.blue);
JTextField tx4 = new JTextField("",15);
tx4.setForeground(Color.BLACK);
p4.add(lb4);
p4.add(tx4);
p5 = new JPanel(gy);
p5.setBackground(Color.MAGENTA);
JLabel lb5 = new JLabel("DIRECCION");
lb5.setForeground(Color.blue);
JTextField tx5 = new JTextField("",15);
tx5.setForeground(Color.BLACK);
p5.add(lb5);
p5.add(tx5);
3. p6 = new JPanel(gy);
p6.setBackground(Color.MAGENTA);
JLabel lb6 = new JLabel("FECHA DE NACIMIENTO");
lb1.setForeground(Color.blue);
JTextField tx6 = new JTextField("",15);
tx6.setForeground(Color.BLACK);
p6.add(lb6);
p6.add(tx6);
p7 = new JPanel(gy);
p7.setBackground(Color.MAGENTA);
JLabel lb7 = new JLabel("SEXO");
lb7.setForeground(Color.blue);
JTextField tx7 = new JTextField("",15);
tx7.setForeground(Color.BLACK);
p7.add(lb7);
p7.add(tx7);
p8 = new JPanel(gy);
p8.setBackground(Color.MAGENTA);
JLabel lb8 = new JLabel("ESTRATO");
lb8.setForeground(Color.blue);
JTextField tx8 = new JTextField("",15);
tx8.setForeground(Color.BLACK);
p8.add(lb8);
p8.add(tx8);
p9 = new JPanel(gy);
p9.setBackground(Color.MAGENTA);
JLabel lb9 = new JLabel("LUGAR DE NACIMIENTO");
lb9.setForeground(Color.blue);
JTextField tx9 = new JTextField("",15);
tx9.setForeground(Color.BLACK);
p9.add(lb9);
p9.add(tx9);
p10 = new JPanel(gy);
p10.setBackground(Color.MAGENTA);
JLabel lb10 = new JLabel("RH");
lb10.setForeground(Color.blue);
JTextField tx10 = new JTextField("",15);
tx10.setForeground(Color.BLACK);
p10.add(lb10);
p10.add(tx10);
4. p11 = new JPanel(gy);
p11.setBackground(Color.MAGENTA);
JLabel lb11 = new JLabel("ESTADO CIVIL");
lb11.setForeground(Color.blue);
JTextField tx11 = new JTextField("",15);
tx11.setForeground(Color.BLACK);
p11.add(lb11);
p11.add(tx11);
p12 = new JPanel(gy);
p12.setBackground(Color.MAGENTA);
JLabel lb12 = new JLabel("CORREO ELECTRONICO");
lb12.setForeground(Color.blue);
JTextField tx12 = new JTextField("",15);
tx12.setForeground(Color.BLACK);
p12.add(lb12);
p12.add(tx12);
p13 = new JPanel(gy);
p13.setBackground(Color.CYAN);
JLabel lb13 = new JLabel("NOMBRE DEL PADRE");
lb13.setForeground(Color.blue);
JTextField tx13 = new JTextField("",15);
tx13.setForeground(Color.BLACK);
p13.add(lb13);
p13.add(tx13);
p14 = new JPanel(gy);
p14.setBackground(Color.CYAN);
JLabel lb14 = new JLabel("DOCUMENTO DEL PADRE ");
lb14.setForeground(Color.blue);
JTextField tx14 = new JTextField("",15);
tx14.setForeground(Color.BLACK);
p14.add(lb14);
p14.add(tx14);
p15 = new JPanel(gy);
p15.setBackground(Color.CYAN);
JLabel lb15 = new JLabel("NOMBRE DE LA MADRE ");
lb15.setForeground(Color.blue);
JTextField tx15 = new JTextField("",15);
tx15.setForeground(Color.BLACK);
p15.add(lb15);
5. p15.add(tx15);
p16 = new JPanel(gy);
p16.setBackground(Color.CYAN);
JLabel lb16 = new JLabel("DOCUMENTO DE LA MADRE");
lb16.setForeground(Color.blue);
JTextField tx16 = new JTextField("",15);
tx16.setForeground(Color.BLACK);
p16.add(lb16);
p16.add(tx16);
p17 = new JPanel(gy);
p17.setBackground(Color.CYAN);
JLabel lb17 = new JLabel("NUMERO DE HERMANOS");
lb17.setForeground(Color.blue);
JTextField tx17 = new JTextField("",15);
tx17.setForeground(Color.BLACK);
p17.add(lb17);
p17.add(tx17);
p18 = new JPanel(gy);
p18.setBackground(Color.CYAN);
JLabel lb18 = new JLabel("NUCLEO FAMILIAR");
lb18.setForeground(Color.blue);
JTextField tx18 = new JTextField("",15);
tx18.setForeground(Color.BLACK);
p18.add(lb18);
p18.add(tx18);
p19 = new JPanel(gy);
p19.setBackground(Color.ORANGE);
JLabel lb19 = new JLabel("NIVEL EDUCATIVO PRIMARIA");
lb19.setForeground(Color.blue);
JTextField tx19 = new JTextField("",15);
tx19 .setForeground(Color.BLACK);
p19.add(lb19);
p19.add(tx19);
p20 = new JPanel(gy);
p20.setBackground(Color.ORANGE);
JLabel lb20 = new JLabel("NOMBRE INSTITUCION");
lb20.setForeground(Color.blue);
JTextField tx20 = new JTextField("",15);
tx20.setForeground(Color.BLACK);
6. p20.add(lb20);
p20.add(tx20);
p21 = new JPanel(gy);
p21.setBackground(Color.ORANGE);
JLabel lb21 = new JLabel("AÑO FINALIZACION");
lb21.setForeground(Color.blue);
JTextField tx21 = new JTextField("",15);
tx21.setForeground(Color.BLACK);
p21.add(lb21);
p21.add(tx21);
p22 = new JPanel(gy);
p22.setBackground(Color.ORANGE);
JLabel lb22 = new JLabel("NIVEL EDUCATIVO BACHILLERATO");
lb22.setForeground(Color.blue);
JTextField tx22 = new JTextField("",15);
tx22.setForeground(Color.BLACK);
p22.add(lb22);
p22.add(tx22);
p23 = new JPanel(gy);
p23.setBackground(Color.ORANGE);
JLabel lb23 = new JLabel("NOMBRE INSTITUCION");
lb23.setForeground(Color.blue);
JTextField tx23 = new JTextField("",15);
tx23.setForeground(Color.BLACK);
p23.add(lb23);
p23.add(tx23);
p24 = new JPanel(gy);
p24.setBackground(Color.ORANGE);
JLabel lb24 = new JLabel("AÑO FINALIZACION");
lb24.setForeground(Color.blue);
JTextField tx24 = new JTextField("",15);
tx24.setForeground(Color.BLACK);
p24.add(lb24);
p24.add(tx24);
p25 = new JPanel(gy);
p25.setBackground(Color.ORANGE);
JLabel lb25 = new JLabel("NIVEL EDUCATIVO PROFESIONAL");
lb25.setForeground(Color.blue);
JTextField tx25 = new JTextField("",15);
7. tx25.setForeground(Color.BLACK);
p25.add(lb25);
p25.add(tx25);
p26 = new JPanel(gy);
p26.setBackground(Color.ORANGE);
JLabel lb26 = new JLabel("CARRERA");
lb26.setForeground(Color.blue);
JTextField tx26 = new JTextField("",15);
tx26.setForeground(Color.BLACK);
p26.add(lb26);
p26.add(tx26);
p27 = new JPanel(gy);
p27.setBackground(Color.ORANGE);
JLabel lb27 = new JLabel("NOMBRE DE INSTITUCION");
lb27.setForeground(Color.blue);
JTextField tx27 = new JTextField("",15);
tx27.setForeground(Color.BLACK);
p27.add(lb27);
p27.add(tx27);
p28 = new JPanel(gy);
p28.setBackground(Color.ORANGE);
JLabel lb28 = new JLabel("AÑO DE FINALIZACION");
lb28.setForeground(Color.blue);
JTextField tx28 = new JTextField("",15);
tx28.setForeground(Color.BLACK);
p28.add(lb28);
p28.add(tx28);
p29 = new JPanel(gy);
p29.setBackground(Color.PINK);
JLabel lb29 = new JLabel("ARS");
lb29.setForeground(Color.blue);
JTextField tx29 = new JTextField("",15);
tx29.setForeground(Color.BLACK);
p29.add(lb29);
p29.add(tx29);
p30 = new JPanel(gy);
p30.setBackground(Color.PINK);
JLabel lb30 = new JLabel("EPS");
lb30.setForeground(Color.blue);
8. JTextField tx30 = new JTextField("",15);
tx30.setForeground(Color.BLACK);
p30.add(lb30);
p30.add(tx30);
p31 = new JPanel(gy);
p31.setBackground(Color.PINK);
JLabel lb31 = new JLabel("SISBEN");
lb31.setForeground(Color.blue);
JTextField tx31 = new JTextField("",15);
tx31.setForeground(Color.BLACK);
p31.add(lb31);
p31.add(tx31);
p32 = new JPanel(gy);
p32.setBackground(Color.PINK);
JLabel lb32 = new JLabel("ALERGIAS");
lb32.setForeground(Color.blue);
JTextField tx32 = new JTextField("",15);
tx32.setForeground(Color.BLACK);
p32.add(lb32);
p32.add(tx32);
p33 = new JPanel(gy);
p33.setBackground(Color.PINK);
JLabel lb33 = new JLabel("CONSUMO DE MEDICAMENTOS");
lb33.setForeground(Color.blue);
JTextField tx33 = new JTextField("",15);
tx33.setForeground(Color.BLACK);
p33.add(lb33);
p33.add(tx33);
// AÑADIR PANELES
cn.add(p1);
cn.add(p2);
cn.add(p3);
cn.add(p4);
cn.add(p5);
// LECTURA DE DATOS INTRODUCIDOS
9. String texto=tx1.getText(); // TEXTO INICIAL
tx1.addActionListener((ActionListener) new Lector1());
tx2.addActionListener((ActionListener) new Lector2());
tx3.addActionListener((ActionListener) new Lector3());
tx4.addActionListener((ActionListener) new Lector4());
tx5.addActionListener((ActionListener) new Lector5());
// FINAL: CIERRE DE VENTANA
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println("ADIOStexto");
}
public static void main(String[] args)
{
Cuestionario frame = new Cuestionario("Ejemplo Formulario");
frame.setVisible(true);
}
// LEE CUANDO SE PRESIONE RETURN EN EL CAMPO CORRESPONDIENTE
class Lector1 implements ActionListener
{
private int a;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("NOMBRE"+ ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector2 implements ActionListener
{
private int b;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("APELLIDO "+ ": ");
System.out.println(((JTextField)e.getSource()).getText());
10. }
}
class Lector3 implements ActionListener
{
private int c;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("DOCUMENTO "+ ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector4 implements ActionListener
{
private int d;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("TELEFONO "+ ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
class Lector5 implements ActionListener
{
private int e;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.print("DIRECCION "+ ": ");
System.out.println(((JTextField)e.getSource()).getText());
}
}
}