Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JComboBox;
- import javax.swing.ButtonGroup;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JRadioButton;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import net.miginfocom.swing.*;
- public class Ventana2 extends JFrame {
- private JPanel contentPane;
- private JTextField txt_nombre;
- private JTextField txt_salario;
- private ButtonGroup botones =new ButtonGroup();
- public Ventana2() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblnombre = new JLabel("nombre");
- lblnombre.setBounds(22, 24, 45, 13);
- contentPane.add(lblnombre);
- txt_nombre = new JTextField();
- txt_nombre.setBounds(105, 21, 96, 19);
- contentPane.add(txt_nombre);
- txt_nombre.setColumns(10);
- JLabel lblEdad = new JLabel("Edad");
- lblEdad.setBounds(22, 88, 45, 13);
- contentPane.add(lblEdad);
- final JComboBox comboBox = new JComboBox();
- comboBox.setModel(new DefaultComboBoxModel(new String[] {"15-25", "25-35", "35-45", "45-55", "M\u00E1s de 55"}));
- comboBox.setBounds(92, 84, 84, 21);
- contentPane.add(comboBox);
- JLabel lblSexo = new JLabel("Sexo");
- lblSexo.setBounds(22, 148, 45, 13);
- contentPane.add(lblSexo);
- final JRadioButton rdbtnMasculino = new JRadioButton("Masculino");
- rdbtnMasculino.setBounds(87, 144, 103, 21);
- contentPane.add(rdbtnMasculino);
- final JRadioButton rdbtnFemenino = new JRadioButton("Femenino");
- rdbtnFemenino.setBounds(188, 144, 103, 21);
- contentPane.add(rdbtnFemenino);
- botones.add(rdbtnMasculino);
- botones.add(rdbtnFemenino);
- JLabel lblSalario = new JLabel("Salario");
- lblSalario.setBounds(22, 191, 45, 13);
- contentPane.add(lblSalario);
- txt_salario = new JTextField();
- txt_salario.setBounds(92, 188, 96, 19);
- contentPane.add(txt_salario);
- txt_salario.setColumns(10);
- JButton btnIngresar = new JButton("Ingresar");
- btnIngresar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String mensaje,sexo = null;
- if(rdbtnMasculino.isSelected())
- {
- sexo="Masculino";
- }
- else {
- if(rdbtnFemenino.isSelected())
- {
- sexo="Femenino";
- }
- }
- mensaje=txt_nombre.getText()+"Que tiene un rango de edad"+comboBox.getSelectedItem()+"de sexo"+sexo+"y que tiene un salario de"+
- txt_salario.getText();
- System.out.println(mensaje);
- }
- });
- btnIngresar.setBounds(206, 187, 85, 21);
- contentPane.add(btnIngresar);
- JButton btnSalir = new JButton("Salir");
- btnSalir.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.exit(0);
- }
- });
- btnSalir.setBounds(206, 232, 85, 21);
- contentPane.add(btnSalir);
- }
- private void initComponents() {
- // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
- // Generated using JFormDesigner Evaluation license - Daniel
- lblnombre = new JLabel();
- txtnombre = new JTextField();
- Edad = new JLabel();
- comboBox = new JComboBox<>();
- lblSexo = new JTextField();
- rdbtnFemenino = new JRadioButton();
- rdbtnMasculino = new JRadioButton();
- lblSalario = new JLabel();
- txtsalario = new JTextField();
- btnIngresar = new JButton();
- btnSalir = new JButton();
- //======== this ========
- setResizable(false);
- var contentPane = getContentPane();
- contentPane.setLayout(new MigLayout(
- "fill,hidemode 3",
- // columns
- "[fill]" +
- "[fill]",
- // rows
- "[]" +
- "[]" +
- "[]" +
- "[]" +
- "[]" +
- "[]"));
- //---- lblnombre ----
- lblnombre.setText("nombre");
- contentPane.add(lblnombre, "cell 0 0");
- contentPane.add(txtnombre, "cell 1 0");
- //---- Edad ----
- Edad.setText("edad");
- contentPane.add(Edad, "cell 0 1");
- //---- comboBox ----
- comboBox.setModel(new DefaultComboBoxModel<>(new String[] {
- "15-25",
- "25-35",
- "45-55",
- "55-65",
- "M\u00e1s de 65"
- }));
- contentPane.add(comboBox, "cell 1 1");
- //---- lblSexo ----
- lblSexo.setText("Sexo:");
- contentPane.add(lblSexo, "cell 0 2");
- //---- rdbtnFemenino ----
- rdbtnFemenino.setText("Femenino");
- contentPane.add(rdbtnFemenino, "cell 1 2");
- //---- rdbtnMasculino ----
- rdbtnMasculino.setText("Masculino");
- contentPane.add(rdbtnMasculino, "cell 1 2");
- //---- lblSalario ----
- lblSalario.setText("Salario");
- contentPane.add(lblSalario, "cell 0 3");
- contentPane.add(txtsalario, "cell 1 3");
- //---- btnIngresar ----
- btnIngresar.setText("Ingresar");
- contentPane.add(btnIngresar, "cell 1 4");
- //---- btnSalir ----
- btnSalir.setText("Salir");
- contentPane.add(btnSalir, "cell 1 4");
- pack();
- setLocationRelativeTo(getOwner());
- // JFormDesigner - End of component initialization //GEN-END:initComponents
- }
- // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
- // Generated using JFormDesigner Evaluation license - Daniel
- private JLabel lblnombre;
- private JTextField txtnombre;
- private JLabel Edad;
- private JComboBox<String> comboBox;
- private JTextField lblSexo;
- private JRadioButton rdbtnFemenino;
- private JRadioButton rdbtnMasculino;
- private JLabel lblSalario;
- private JTextField txtsalario;
- private JButton btnIngresar;
- private JButton btnSalir;
- // JFormDesigner - End of variables declaration //GEN-END:variables
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement