
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.Vector;
import java.lang.*;

// Hat alle wichtige Listener implementiert
// und den Mouse-Click 

public class Listener_Bsp02 extends JFrame {

    JPanel pnCenter = new JPanel();
    JPanel pnSouth = new JPanel();

    JPanel [] panels = new JPanel[2];
    JPanel MouseMovePanel=null;

  //Frame konstruieren
  public Listener_Bsp02() {
    this.setSize(new Dimension(500, 300));
    this.setTitle("Frame Listener JFrame_Bsp02");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }


  //Initialisierung der Komponente
  private void setGUI()  {
    JButton bnOk = new JButton("Ok");
    JTextField editzeile = new JTextField("hier ist ein Text");
    JPanel pn = new JPanel();
    pn.add(editzeile);
    pn.add(bnOk);
    pn.setLayout( new FlowLayout() );
    bnOk.setFont( new Font("Arial", Font.PLAIN,24)  );
    editzeile.setFont( new Font("Arial", Font.PLAIN,24)  );

    this.getContentPane().add(pn, BorderLayout.NORTH);

    pnCenter.setBackground(Color.RED);
    this.getContentPane().add(pnCenter, BorderLayout.CENTER);

    pnSouth.setBackground(Color.BLUE);
    this.getContentPane().add(pnSouth, BorderLayout.SOUTH);
    panels[0]=pnCenter;
    panels[1]=pnSouth;

    JButton bnEsc = new JButton("Abbrechen");
    pnSouth.setLayout( new FlowLayout() );
    pnSouth.add( bnEsc );



    for (int i=0; i<panels.length; i++) {    
       panels[i].addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
   
         public void mouseDragged(MouseEvent e) {
           // this_mouseDragged(e);
         }
   
         public void mouseMoved(MouseEvent e) {
           pn13_mouseMoved(e);
         }
       });
       panels[i].addMouseListener(new java.awt.event.MouseAdapter() {
   
         public void mouseClicked(MouseEvent e) {
           pn13_mouseClicked(e);
         }
   
         public void mouseEntered(MouseEvent e) {
           pn13_mouseEntered(e);
         }
   
         public void mouseExited(MouseEvent e) {
           pn13_mouseExited(e);
         }
   
         public void mousePressed(MouseEvent e) {
           pn13_mousePressed(e);
         }
   
         public void mouseReleased(MouseEvent e) {
           pn13_mouseReleased(e);
         }
       });  // pn1
   
       panels[i].addKeyListener(new java.awt.event.KeyAdapter() {
         public void keyPressed(KeyEvent e) {
           pn13_keyPressed(e);
         }
   
         public void keyReleased(KeyEvent e) {
           pn13_keyReleased(e);
         }
   
         public void keyTyped(KeyEvent e) {
           pn13_keyTyped(e);
         }
       });
    } // for panels

    this.addWindowListener(new java.awt.event.WindowAdapter() {

      public void windowActivated(WindowEvent e) {
        this_windowActivated(e);
      }

      public void windowClosed(WindowEvent e) {
        this_windowClosed(e);
      }

      public void windowClosing(WindowEvent e) {
        this_windowClosing(e);
      }

      public void windowDeactivated(WindowEvent e) {
        this_windowDeactivated(e);
      }

      public void windowDeiconified(WindowEvent e) {
        this_windowDeiconified(e);
      }

      public void windowIconified(WindowEvent e) {
        this_windowIconified(e);
      }

      public void windowOpened(WindowEvent e) {
        this_windowOpened(e);
      }
    });
    this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {

      public void mouseDragged(MouseEvent e) {
        this_mouseDragged(e);
      }

      public void mouseMoved(MouseEvent e) {
        this_mouseMoved(e);
      }
    });


    this.addMouseListener(new java.awt.event.MouseAdapter() {

      public void mouseClicked(MouseEvent e) {
        this_mouseClicked(e);
      }

      public void mouseEntered(MouseEvent e) {
        this_mouseEntered(e);
      }

      public void mouseExited(MouseEvent e) {
        this_mouseExited(e);
      }

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

      public void mouseReleased(MouseEvent e) {
        this_mouseReleased(e);
      }
    });
    this.addKeyListener(new java.awt.event.KeyAdapter() {

      public void keyPressed(KeyEvent e) {
        this_keyPressed(e);
      }

      public void keyReleased(KeyEvent e) {
        this_keyReleased(e);
      }

      public void keyTyped(KeyEvent e) {
        this_keyTyped(e);
      }
    });
    this.addFocusListener(new java.awt.event.FocusAdapter() {

      public void focusGained(FocusEvent e) {
        this_focusGained(e);
      }

      public void focusLost(FocusEvent e) {
        this_focusLost(e);
      }
    });

    editzeile.addMouseListener(new java.awt.event.MouseAdapter() {

      public void mouseClicked(MouseEvent e) {
        editzeile_mouseClicked(e);
      }

      public void mouseEntered(MouseEvent e) {
        editzeile_mouseEntered(e);
      }

      public void mouseExited(MouseEvent e) {
        editzeile_mouseExited(e);
      }

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

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


    bnOk.addMouseListener(new java.awt.event.MouseAdapter() {

      public void mouseClicked(MouseEvent e) {
        bnok_mouseClicked(e);
      }

      public void mouseEntered(MouseEvent e) {
        bnok_mouseEntered(e);
      }

      public void mouseExited(MouseEvent e) {
        bnok_mouseExited(e);
      }

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

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

  }  // setGUI




  void this_focusGained(FocusEvent e) {
    System.out.println("focusGained, focus erhalten");
  }

  void this_focusLost(FocusEvent e) {
    System.out.println("focusLost");
  }

  void this_keyPressed(KeyEvent e) {
    System.out.println("keyPressed");
  }

  void this_keyReleased(KeyEvent e) {
    System.out.println("keyReleased");
  }

  void this_keyTyped(KeyEvent e) {
    System.out.println("keyTyped");
  }

  void this_mouseClicked(MouseEvent e) {
    System.out.println("mouseClicked");
    // e.getSource()
  }
  void this_mouseEntered(MouseEvent e) {
    System.out.println("mouseEntered");
  }

  void this_mouseExited(MouseEvent e) {
    System.out.println("mouseExited");
  }
  void this_mousePressed(MouseEvent e) {
    System.out.println("mousePressed");
  }

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


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


  void this_mouseMoved(MouseEvent e) {
    System.out.println("mouseMoved");
  }


  void this_windowActivated(WindowEvent e) {
    System.out.println("windowActivated");
  }

  void this_windowClosed(WindowEvent e) {
    System.out.println("windowClosed");
  }

  void this_windowClosing(WindowEvent e) {
    System.out.println("windowClosing");
  }

  void this_windowDeactivated(WindowEvent e) {
    System.out.println("windowDeactivated");
  }

  void this_windowDeiconified(WindowEvent e) {
    System.out.println("windowDeiconified");
  }

  void this_windowIconified(WindowEvent e) {
    System.out.println("windowIconified");
  }

  void this_windowOpened(WindowEvent e) {
    System.out.println("windowOpened");
  }


   void bnok_mouseClicked(MouseEvent e) {
    System.out.println("Mausklick im Schalter");
   }

   void bnok_mouseEntered(MouseEvent e) {
    System.out.println("Maus Enter im Schalter");
   }


   void bnok_mouseExited(MouseEvent e) {
    System.out.println("Maus Exit im Schalter");

  }

  void bnok_mousePressed(MouseEvent e) {
    System.out.println("Maus Press im Schalter");
  }

  void bnok_mouseReleased(MouseEvent e) {
      System.out.println("Maus Release im Schalter");
  }




   void editzeile_mouseClicked(MouseEvent e) {
    System.out.println("Mausklick der Editzeile");
   }

   void editzeile_mouseEntered(MouseEvent e) {
    System.out.println("Maus Enter der Editzeile");
   }


   void editzeile_mouseExited(MouseEvent e) {
    System.out.println("Maus Exit der Editzeile");

  }

  void editzeile_mousePressed(MouseEvent e) {
    System.out.println("Maus Press der Editzeile");
  }

  void editzeile_mouseReleased(MouseEvent e) {
      System.out.println("Maus Release in der Editzeile");
  }



 String getName(Object pn0) {
   JPanel pn = (JPanel) pn0;
   if ( pn.equals(pnCenter) )
     return "Panel Center";
   else if (pn.equals(pnSouth))
          return "PanelSouth";
        else return "Fehlerhaftes Panels";
  }
  

  void pn13_keyPressed(KeyEvent e) {
    System.out.println("pn13: keyPressed: "+getName( e.getSource()) );
  }

  void pn13_keyReleased(KeyEvent e) {
    System.out.println("pn13: keyReleased: "+getName(e.getSource()) );
  }

  void pn13_keyTyped(KeyEvent e) {
    System.out.println("pn13: keyTyped: "+getName(e.getSource())  );
  }



  void pn13_mouseClicked(MouseEvent e) {
    System.out.println("pn13: mouseClicked: "+getName(e.getSource())  );
  }



  void pn13_mouseEntered(MouseEvent e) {
    System.out.println("pn13: mouseEntered: "+getName(e.getSource())  );
  }

  void pn13_mouseExited(MouseEvent e) {
    System.out.println("pn13: mouseExited: "+getName(e.getSource())  );
  }

   // Nur einmal ausgeben
  void pn13_mouseMoved(MouseEvent e) {
    JPanel pn = (JPanel) e.getSource();
    if ( (MouseMovePanel==null)  || (!pn.equals(MouseMovePanel)) )
      System.out.println("pn13: mouseMoved: "+getName(e.getSource())  );
    MouseMovePanel=pn;
  }

  void pn13_mousePressed(MouseEvent e) {
    System.out.println("pn1: mousePressed: "+getName(e.getSource())  );
  }

  void pn13_mouseReleased(MouseEvent e) {
    System.out.println("pn13: mouseReleased: "+getName(e.getSource()) );
  }


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



}
