Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Formulario5
1. package formulario;
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;
public class Formulario 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 Formulario(String nameFormulario)
{
super(nameFormulario);
setSize(new Dimension(300,300));
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.PINK);
JLabel lb1 = new JLabel("Nombre");
lb1.setForeground(Color.black);
2. JTextField tx1 = new JTextField("Escribir-aqui",10);
tx1.setForeground(Color.RED);
p1.add(lb1);
p1.add(tx1);
p2 = new JPanel(gy);
p2.setBackground(Color.PINK);
JLabel lb2 = new JLabel("Apellidos");
lb2.setForeground(Color.black);
JTextField tx2 = new JTextField("escriba aqui",15);
tx2.setForeground(Color.RED);
p2.add(lb2);
p2.add(tx2);
p3 = new JPanel(gy);
p3.setBackground(Color.PINK);
JLabel lb3 = new JLabel("Edad");
lb3.setForeground(Color.black);
JTextField tx3 = new JTextField("escriba aqui",15);
tx3.setForeground(Color.RED);
p3.add(lb3);
p3.add(tx3);
p4 = new JPanel(gy);
p4.setBackground(Color.PINK);
JLabel lb4 = new JLabel("direccion");
lb4.setForeground(Color.black);
JTextField tx4 = new JTextField("escriba aqui",15);
tx4.setForeground(Color.RED);
p4.add(lb4);
p4.add(tx4);
p5 = new JPanel(gy);
p5.setBackground(Color.PINK);
JLabel lb5 = new JLabel("telefono");
lb5.setForeground(Color.black);
JTextField tx5 = new JTextField("escriba aqui",15);
tx5.setForeground(Color.RED);
p5.add(lb5);
p5.add(tx5);
p6 = new JPanel(gy);
p6.setBackground(Color.PINK);
3. JLabel lb6 = new JLabel("de tus hermanos eres el");
lb6.setForeground(Color.black);
JTextField tx6 = new JTextField("escriba aqui",15);
tx6.setForeground(Color.RED);
p6.add(lb6);
p6.add(tx6);
p7 = new JPanel(gy);
p7.setBackground(Color.PINK);
JLabel lb7 = new JLabel("color favorito");
lb7.setForeground(Color.black);
JTextField tx7 = new JTextField("escriba aqui",15);
tx7.setForeground(Color.RED);
p7.add(lb7);
p7.add(tx7);
p8= new JPanel(gy);
p8.setBackground(Color.PINK);
JLabel lb8 = new JLabel("tu RH");
lb8.setForeground(Color.black);
JTextField tx8 = new JTextField("escriba aqui",15);
tx8.setForeground(Color.RED);
p8.add(lb8);
p8.add(tx8);
// 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);
// LECTURA DE DATOS INTRODUCIDOS
4. String texto=tx1.getText(); // TEXTO INICIAL
tx1.addActionListener(new Lector1());
tx2.addActionListener(new Lector2());
// FINAL: CIERRE DE VENTANA
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
Formulario frame = new Formulario("Ejemplo Formulario");
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.println(((JTextField)e.getSource()).getText());
}
}
class Lector2 implements ActionListener
{
private int i;
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println(((JTextField)e.getSource()).getText());
}
}