Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import javax.swing.JLabel;
  8. import javax.swing.JTextField;
  9. import javax.swing.JComboBox;
  10. import javax.swing.ButtonGroup;
  11. import javax.swing.DefaultComboBoxModel;
  12. import javax.swing.JRadioButton;
  13. import javax.swing.JButton;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.ActionEvent;
  16. import net.miginfocom.swing.*;
  17.  
  18. public class Ventana2 extends JFrame {
  19.  
  20. private JPanel contentPane;
  21. private JTextField txt_nombre;
  22. private JTextField txt_salario;
  23. private ButtonGroup botones =new ButtonGroup();
  24.  
  25. public Ventana2() {
  26. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27. setBounds(100, 100, 450, 300);
  28. contentPane = new JPanel();
  29. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  30. setContentPane(contentPane);
  31. contentPane.setLayout(null);
  32.  
  33. JLabel lblnombre = new JLabel("nombre");
  34. lblnombre.setBounds(22, 24, 45, 13);
  35. contentPane.add(lblnombre);
  36.  
  37. txt_nombre = new JTextField();
  38. txt_nombre.setBounds(105, 21, 96, 19);
  39. contentPane.add(txt_nombre);
  40. txt_nombre.setColumns(10);
  41.  
  42. JLabel lblEdad = new JLabel("Edad");
  43. lblEdad.setBounds(22, 88, 45, 13);
  44. contentPane.add(lblEdad);
  45.  
  46. final JComboBox comboBox = new JComboBox();
  47. comboBox.setModel(new DefaultComboBoxModel(new String[] {"15-25", "25-35", "35-45", "45-55", "M\u00E1s de 55"}));
  48. comboBox.setBounds(92, 84, 84, 21);
  49. contentPane.add(comboBox);
  50.  
  51. JLabel lblSexo = new JLabel("Sexo");
  52. lblSexo.setBounds(22, 148, 45, 13);
  53. contentPane.add(lblSexo);
  54.  
  55. final JRadioButton rdbtnMasculino = new JRadioButton("Masculino");
  56. rdbtnMasculino.setBounds(87, 144, 103, 21);
  57. contentPane.add(rdbtnMasculino);
  58.  
  59. final JRadioButton rdbtnFemenino = new JRadioButton("Femenino");
  60. rdbtnFemenino.setBounds(188, 144, 103, 21);
  61. contentPane.add(rdbtnFemenino);
  62.  
  63. botones.add(rdbtnMasculino);
  64. botones.add(rdbtnFemenino);
  65.  
  66.  
  67.  
  68. JLabel lblSalario = new JLabel("Salario");
  69. lblSalario.setBounds(22, 191, 45, 13);
  70. contentPane.add(lblSalario);
  71.  
  72. txt_salario = new JTextField();
  73. txt_salario.setBounds(92, 188, 96, 19);
  74. contentPane.add(txt_salario);
  75. txt_salario.setColumns(10);
  76.  
  77. JButton btnIngresar = new JButton("Ingresar");
  78. btnIngresar.addActionListener(new ActionListener() {
  79. public void actionPerformed(ActionEvent e) {
  80. String mensaje,sexo = null;
  81.  
  82. if(rdbtnMasculino.isSelected())
  83. {
  84. sexo="Masculino";
  85. }
  86. else {
  87. if(rdbtnFemenino.isSelected())
  88. {
  89. sexo="Femenino";
  90. }
  91. }
  92. mensaje=txt_nombre.getText()+"Que tiene un rango de edad"+comboBox.getSelectedItem()+"de sexo"+sexo+"y que tiene un salario de"+
  93. txt_salario.getText();
  94. System.out.println(mensaje);
  95. }
  96. });
  97. btnIngresar.setBounds(206, 187, 85, 21);
  98. contentPane.add(btnIngresar);
  99.  
  100. JButton btnSalir = new JButton("Salir");
  101. btnSalir.addActionListener(new ActionListener() {
  102. public void actionPerformed(ActionEvent arg0) {
  103. System.exit(0);
  104. }
  105. });
  106. btnSalir.setBounds(206, 232, 85, 21);
  107. contentPane.add(btnSalir);
  108. }
  109.  
  110. private void initComponents() {
  111. // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
  112. // Generated using JFormDesigner Evaluation license - Daniel
  113. lblnombre = new JLabel();
  114. txtnombre = new JTextField();
  115. Edad = new JLabel();
  116. comboBox = new JComboBox<>();
  117. lblSexo = new JTextField();
  118. rdbtnFemenino = new JRadioButton();
  119. rdbtnMasculino = new JRadioButton();
  120. lblSalario = new JLabel();
  121. txtsalario = new JTextField();
  122. btnIngresar = new JButton();
  123. btnSalir = new JButton();
  124.  
  125. //======== this ========
  126. setResizable(false);
  127. var contentPane = getContentPane();
  128. contentPane.setLayout(new MigLayout(
  129. "fill,hidemode 3",
  130. // columns
  131. "[fill]" +
  132. "[fill]",
  133. // rows
  134. "[]" +
  135. "[]" +
  136. "[]" +
  137. "[]" +
  138. "[]" +
  139. "[]"));
  140.  
  141. //---- lblnombre ----
  142. lblnombre.setText("nombre");
  143. contentPane.add(lblnombre, "cell 0 0");
  144. contentPane.add(txtnombre, "cell 1 0");
  145.  
  146. //---- Edad ----
  147. Edad.setText("edad");
  148. contentPane.add(Edad, "cell 0 1");
  149.  
  150. //---- comboBox ----
  151. comboBox.setModel(new DefaultComboBoxModel<>(new String[] {
  152. "15-25",
  153. "25-35",
  154. "45-55",
  155. "55-65",
  156. "M\u00e1s de 65"
  157. }));
  158. contentPane.add(comboBox, "cell 1 1");
  159.  
  160. //---- lblSexo ----
  161. lblSexo.setText("Sexo:");
  162. contentPane.add(lblSexo, "cell 0 2");
  163.  
  164. //---- rdbtnFemenino ----
  165. rdbtnFemenino.setText("Femenino");
  166. contentPane.add(rdbtnFemenino, "cell 1 2");
  167.  
  168. //---- rdbtnMasculino ----
  169. rdbtnMasculino.setText("Masculino");
  170. contentPane.add(rdbtnMasculino, "cell 1 2");
  171.  
  172. //---- lblSalario ----
  173. lblSalario.setText("Salario");
  174. contentPane.add(lblSalario, "cell 0 3");
  175. contentPane.add(txtsalario, "cell 1 3");
  176.  
  177. //---- btnIngresar ----
  178. btnIngresar.setText("Ingresar");
  179. contentPane.add(btnIngresar, "cell 1 4");
  180.  
  181. //---- btnSalir ----
  182. btnSalir.setText("Salir");
  183. contentPane.add(btnSalir, "cell 1 4");
  184. pack();
  185. setLocationRelativeTo(getOwner());
  186. // JFormDesigner - End of component initialization //GEN-END:initComponents
  187. }
  188.  
  189. // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
  190. // Generated using JFormDesigner Evaluation license - Daniel
  191. private JLabel lblnombre;
  192. private JTextField txtnombre;
  193. private JLabel Edad;
  194. private JComboBox<String> comboBox;
  195. private JTextField lblSexo;
  196. private JRadioButton rdbtnFemenino;
  197. private JRadioButton rdbtnMasculino;
  198. private JLabel lblSalario;
  199. private JTextField txtsalario;
  200. private JButton btnIngresar;
  201. private JButton btnSalir;
  202. // JFormDesigner - End of variables declaration //GEN-END:variables
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement