/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Capitulo_6.Dibujo2;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

/**
 *
 * @author felix
 */
public class SeleccionPanel extends JPanel implements ActionListener{
    static private int seleccion;
    private String nombres[];
    
    public SeleccionPanel(String Nombre, String[] opciones, int N) {
        super(new GridLayout(N/2, 2));
        int i;
        nombres = new String[N];
        
        for(i=0; i<N; i++)
            nombres[i] = opciones[i];
        
        this.setBackground(Color.lightGray);
        this.setBorder(BorderFactory.createTitledBorder(Nombre));
        ButtonGroup group = new ButtonGroup();
        JRadioButton option;
        
        for(i=0; i<N; i++) {
            option = new JRadioButton(opciones[i]);
            option.addActionListener(this);
            group.add(option);
            add(option);
        }
    }

    public void actionPerformed(ActionEvent arg0) {
        int i;
        
        for(i=0; i<nombres.length; i++) {
            if(nombres[i].equals(arg0.getActionCommand())){
                seleccion = i;
                break;
            }
        }
        System.out.println(nombres[seleccion]);
    }
}
