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

import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author kleisar
 */
public class MyButtons extends JFrame implements MouseListener {

    public MyButtons() {
        super("My Game!");
        this.add(addButtons(5, 3));

        this.pack();
        this.setVisible(true);
    }

    private JPanel addButtons(int rows, int columns) {
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(rows, columns));
        for (int i = 0; i < rows * columns; i++) {
            JButton but = new JButton(String.valueOf(i));
            but.addMouseListener(this);
            panel.add(but);
        }
        return panel;
    }

    public static void main(String[] args) {
        new MyButtons();
    }

    public void mouseClicked(MouseEvent arg0) {
        JOptionPane.showMessageDialog(null, "Button pressed!", null, JOptionPane.INFORMATION_MESSAGE);
        //System.out.println("button pressed");
    }

    public void mousePressed(MouseEvent arg0) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseReleased(MouseEvent arg0) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseEntered(MouseEvent arg0) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent arg0) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }
}
