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

package Ventana;

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.JButton;
import javax.swing.JPanel;

/**
 *
 * @author felix
 */
public class Botones2 extends JPanel implements ActionListener {
    static private int botonPrecionado;
    private String nombres[];
    
    public Botones2(String unTitulo, String unNombre[], int N) {
        super(new GridLayout(N/2, 2));
        int i;
        
        nombres = new String[N];
        
        for(i=0; i<N; i++) 
            nombres[i] = unNombre[i];
        
        this.setBackground(Color.lightGray);
        this.setBorder(BorderFactory.createTitledBorder(unTitulo));
        
        JButton b;
        
        for(i=0; i<N; i++) {
            b = new JButton(unNombre[i]);
            b.addActionListener(this);
            this.add(b);
        }       
    }

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