
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

// Beispiel mit GridLayout
// mit verschiedenen Events

public class GridLayoutEvents extends JFrame {
     JPanel panel;


  //Frame konstruieren
  public GridLayoutEvents() {
    setSize(500, 300);
    setTitle("GridLayoutEvents");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  private void setGUI() {
     JButton bn;
     Integer I = new Integer(0);


    panel = new JPanel();
    panel.setLayout ( new GridLayout(5,3) );
    this.getContentPane().add(panel, BorderLayout.CENTER);
    for (int i=0; i<17; i++) {
      bn = new JButton( Integer.toString(i+1)  );
      bn.setFont( new Font("Arial", Font.BOLD,18)  );
      panel.add(bn);
      setEvent(bn);
    }
  } // setGUI


  private void setEvent(JButton bn){
    bn.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
      public void mouseDragged(MouseEvent e) {
        this_mouseDragged(e);
      }
    });

    bn.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        this_mouseClicked(e);
      }
      

      public void mousePressed(MouseEvent e) {
        this_mousePressed(e);
      }

      public void mouseReleased(MouseEvent e) {
        this_mouseReleased(e);
      }
    });
  }




  void this_mouseClicked(MouseEvent e) {
    System.out.println("MouseClick");
  }

  void this_mouseDragged(MouseEvent e) {
    System.out.println("MouseDragged");
  }

  void this_mousePressed(MouseEvent e) {
    System.out.println("MousePressed");
  }

  void this_mouseReleased(MouseEvent e) {
    System.out.println("MouseRelease");
  }

  public static void main(String[] args) {
    GridLayoutEvents frame = new GridLayoutEvents();
    frame.setVisible(true);
  }

}
