carlos0722

Untitled

Feb 28th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.31 KB | None | 0 0
  1. package problems01;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JRadioButton;
  7. import java.awt.BorderLayout;
  8. import javax.swing.JPanel;
  9. import java.awt.Panel;
  10. import javax.swing.SwingConstants;
  11. import javax.swing.event.ChangeEvent;
  12. import javax.swing.event.ChangeListener;
  13. import javax.swing.Action;
  14. import javax.swing.ButtonGroup;
  15. import javax.swing.GroupLayout;
  16. import javax.swing.GroupLayout.Alignment;
  17. import java.awt.Checkbox;
  18. import java.awt.TextField;
  19. import javax.swing.JComboBox;
  20. import javax.swing.LayoutStyle.ComponentPlacement;
  21. import java.awt.Choice;
  22. import javax.swing.JSpinner;
  23. import javax.swing.JCheckBox;
  24. import javax.swing.JTextField;
  25. import java.awt.event.ActionListener;
  26. import java.awt.event.ActionEvent;
  27.  
  28. public class problema1 implements ChangeListener{
  29.  
  30.     private JFrame frame;
  31.     private final JRadioButton button_2 = new JRadioButton("opcion 2");
  32.    
  33.  JRadioButton button4; JRadioButton button_3;JRadioButton button_1;JRadioButton button_1_espe;JRadioButton button_2_espe;JRadioButton button_3_espe;
  34.  JCheckBox check1; JCheckBox check2;JCheckBox check3;
  35.  
  36.  
  37.  
  38.  
  39. private JTextField txtText;
  40. private JCheckBox check_6_espe;
  41. private JTextField textField_espe;
  42.  
  43.  
  44.  
  45.  
  46.    
  47.  
  48.     /**
  49.      * Launch the application.
  50.      */
  51.     public static void main(String[] args) {
  52.         EventQueue.invokeLater(new Runnable() {
  53.             public void run() {
  54.                 try {
  55.                     problema1 window = new problema1();
  56.                     window.frame.setVisible(true);
  57.                 } catch (Exception e) {
  58.                     e.printStackTrace();
  59.                 }
  60.             }
  61.         });
  62.     }
  63.  
  64.     /**
  65.      * Create the application.
  66.      */
  67.     public problema1() {
  68.         initialize();
  69.     }
  70.  
  71.     /**
  72.      * Initialize the contents of the frame.
  73.      */
  74.     private void initialize() {
  75.         frame = new JFrame();
  76.         frame.setBounds(100, 100, 462, 391);
  77.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  78.         ButtonGroup Grupos=new ButtonGroup();
  79.  
  80.        
  81.         Panel Original = new Panel();
  82.        
  83.         button_3 = new JRadioButton("opcion 3");
  84.         button_3.addChangeListener(this);
  85.         button_2.setVerticalAlignment(SwingConstants.TOP);
  86.         button_2.addChangeListener(this);
  87.        
  88.         button_1 = new JRadioButton("opcion1");
  89.         button_1.addActionListener(new ActionListener() {
  90.             public void actionPerformed(ActionEvent e) {
  91.                
  92.                
  93.             }
  94.         });
  95.        
  96. //button_1.addChangeListener(this);
  97.        
  98.         JCheckBox check1 = new JCheckBox("opcion 4");
  99.        
  100.         JCheckBox check2 = new JCheckBox("opcion 5");
  101.        
  102.         JCheckBox check3 = new JCheckBox("opcion 6");
  103.        
  104.         txtText = new JTextField();
  105.         txtText.setColumns(10);
  106.        
  107.         JSpinner spinner = new JSpinner();
  108.        
  109.         JComboBox comboBox = new JComboBox();
  110.         GroupLayout gl_Original = new GroupLayout(Original);
  111.         gl_Original.setHorizontalGroup(
  112.             gl_Original.createParallelGroup(Alignment.LEADING)
  113.                 .addGroup(gl_Original.createSequentialGroup()
  114.                     .addContainerGap()
  115.                     .addGroup(gl_Original.createParallelGroup(Alignment.LEADING)
  116.                         .addGroup(gl_Original.createParallelGroup(Alignment.LEADING, false)
  117.                             .addGroup(gl_Original.createSequentialGroup()
  118.                                 .addComponent(button_2)
  119.                                 .addGap(18)
  120.                                 .addComponent(check2)
  121.                                 .addGap(18)
  122.                                 .addComponent(comboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  123.                             .addGroup(gl_Original.createSequentialGroup()
  124.                                 .addComponent(button_3)
  125.                                 .addGap(18)
  126.                                 .addComponent(check3)
  127.                                 .addGap(18)
  128.                                 .addComponent(spinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
  129.                         .addGroup(gl_Original.createSequentialGroup()
  130.                             .addComponent(button_1)
  131.                             .addGap(18)
  132.                             .addComponent(check1)
  133.                             .addGap(18)
  134.                             .addComponent(txtText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
  135.                     .addContainerGap(190, Short.MAX_VALUE))
  136.         );
  137.         gl_Original.setVerticalGroup(
  138.             gl_Original.createParallelGroup(Alignment.LEADING)
  139.                 .addGroup(gl_Original.createSequentialGroup()
  140.                     .addContainerGap()
  141.                     .addGroup(gl_Original.createParallelGroup(Alignment.BASELINE)
  142.                         .addComponent(button_1)
  143.                         .addComponent(check1)
  144.                         .addComponent(txtText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  145.                     .addGap(18)
  146.                     .addGroup(gl_Original.createParallelGroup(Alignment.BASELINE)
  147.                         .addComponent(button_2)
  148.                         .addComponent(check2)
  149.                         .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  150.                     .addGap(18)
  151.                     .addGroup(gl_Original.createParallelGroup(Alignment.BASELINE)
  152.                         .addComponent(button_3)
  153.                         .addComponent(check3)
  154.                         .addComponent(spinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  155.                     .addContainerGap(46, Short.MAX_VALUE))
  156.         );
  157.         Original.setLayout(gl_Original);
  158.        
  159.         JPanel espejo = new JPanel();
  160.         GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
  161.         groupLayout.setHorizontalGroup(
  162.             groupLayout.createParallelGroup(Alignment.LEADING)
  163.                 .addComponent(Original, GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
  164.                 .addComponent(espejo, GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
  165.         );
  166.         groupLayout.setVerticalGroup(
  167.             groupLayout.createParallelGroup(Alignment.LEADING)
  168.                 .addGroup(groupLayout.createSequentialGroup()
  169.                     .addComponent(Original, GroupLayout.PREFERRED_SIZE, 161, GroupLayout.PREFERRED_SIZE)
  170.                     .addPreferredGap(ComponentPlacement.RELATED)
  171.                     .addComponent(espejo, GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))
  172.         );
  173.        
  174.          button_1_espe = new JRadioButton("opcion 1");
  175.         button_1_espe.setEnabled(false);
  176.        
  177.         JRadioButton button_2_espe = new JRadioButton("opcion 2");
  178.         button_2_espe.setEnabled(false);
  179.         button_2_espe.setVerticalAlignment(SwingConstants.TOP);
  180.        
  181.         JRadioButton button3_espe = new JRadioButton("opcion 3");
  182.         button3_espe.setEnabled(false);
  183.        
  184.         JCheckBox check_4_espe = new JCheckBox("opcion 4");
  185.         check_4_espe.setEnabled(false);
  186.        
  187.         JCheckBox check_5_espe = new JCheckBox("opcion 5");
  188.         check_5_espe.setEnabled(false);
  189.        
  190.         check_6_espe = new JCheckBox("opcion 6");
  191.         check_6_espe.setEnabled(false);
  192.        
  193.         textField_espe = new JTextField();
  194.         textField_espe.setEnabled(false);
  195.         textField_espe.setColumns(10);
  196.        
  197.         JComboBox comboBox_espe = new JComboBox();
  198.         comboBox_espe.setEnabled(false);
  199.        
  200.         JSpinner spinner_espe = new JSpinner();
  201.         spinner_espe.setEnabled(false);
  202.         GroupLayout gl_espejo = new GroupLayout(espejo);
  203.         gl_espejo.setHorizontalGroup(
  204.             gl_espejo.createParallelGroup(Alignment.LEADING)
  205.                 .addGroup(gl_espejo.createSequentialGroup()
  206.                     .addContainerGap()
  207.                     .addGroup(gl_espejo.createParallelGroup(Alignment.LEADING)
  208.                         .addGroup(gl_espejo.createSequentialGroup()
  209.                             .addGroup(gl_espejo.createParallelGroup(Alignment.LEADING)
  210.                                 .addComponent(button_2_espe, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE)
  211.                                 .addComponent(button_1_espe))
  212.                             .addGap(18)
  213.                             .addGroup(gl_espejo.createParallelGroup(Alignment.LEADING)
  214.                                 .addGroup(gl_espejo.createSequentialGroup()
  215.                                     .addComponent(check_5_espe)
  216.                                     .addGap(18)
  217.                                     .addComponent(comboBox_espe, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE))
  218.                                 .addGroup(gl_espejo.createSequentialGroup()
  219.                                     .addComponent(check_4_espe)
  220.                                     .addGap(18)
  221.                                     .addComponent(textField_espe, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
  222.                             .addContainerGap(188, Short.MAX_VALUE))
  223.                         .addGroup(gl_espejo.createSequentialGroup()
  224.                             .addComponent(button3_espe)
  225.                             .addGap(18)
  226.                             .addComponent(check_6_espe)
  227.                             .addGap(18)
  228.                             .addComponent(spinner_espe, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  229.                             .addContainerGap(244, Short.MAX_VALUE))))
  230.         );
  231.         gl_espejo.setVerticalGroup(
  232.             gl_espejo.createParallelGroup(Alignment.LEADING)
  233.                 .addGroup(gl_espejo.createSequentialGroup()
  234.                     .addGap(35)
  235.                     .addGroup(gl_espejo.createParallelGroup(Alignment.BASELINE)
  236.                         .addComponent(check_4_espe)
  237.                         .addComponent(button_1_espe)
  238.                         .addComponent(textField_espe, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  239.                     .addGap(10)
  240.                     .addGroup(gl_espejo.createParallelGroup(Alignment.BASELINE)
  241.                         .addComponent(check_5_espe)
  242.                         .addComponent(button_2_espe)
  243.                         .addComponent(comboBox_espe, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  244.                     .addGap(18)
  245.                     .addGroup(gl_espejo.createParallelGroup(Alignment.BASELINE)
  246.                         .addComponent(button3_espe)
  247.                         .addComponent(check_6_espe)
  248.                         .addComponent(spinner_espe, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  249.                     .addGap(36))
  250.         );
  251.         espejo.setLayout(gl_espejo);
  252.         frame.getContentPane().setLayout(groupLayout);
  253.            
  254.  
  255.        
  256.         Grupos.add(button_1);
  257.         Grupos.add(button_2);
  258.         Grupos.add(button_3);
  259.         //checkes
  260.         Grupos.add(check3);
  261.         Grupos.add(check2);
  262.         Grupos.add(check1);
  263.    
  264.        
  265.    
  266.  
  267.        
  268.     }
  269.  
  270.     @Override
  271.     public void stateChanged(ChangeEvent e) {
  272.         // TODO Auto-generated method stub
  273.         //if(button_1.isSelected()) {
  274.             //button_1_espe.setSelected(true);
  275.         //}
  276.         if(button_3.isSelected()){
  277.             button_3_espe.setSelected(true);
  278.         }
  279.         if(button_2.isSelected()) {
  280.             button_2_espe.setSelected(true);
  281.         }
  282.        
  283.     }
  284. }
  285.  
Advertisement
Add Comment
Please, Sign In to add comment