//Titel:	       Dialog-Fenster mit Action-Listener
//Version:	    1.0
//Copyright:	 (c) 2011, 25.10.2011 
//Autor:	       by M. Wilhelm
//Organisation: HS-Harz
//Beschreibung: Zeigt den Action-Listener mit anonymer Instanz und zwei Events


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


public class Action5 extends JFrame {

  JButton BnOk = new JButton("Ok");
  JButton BnEsc = new JButton("Abbruch");

  public Action5() {
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  private void setGUI() {
    setSize(400, 430);
    setTitle("JFrame als Dialog");

    BnOk.setFont( new Font("Arial", Font.BOLD,18)  );
    BnEsc.setFont( new Font("Arial", Font.BOLD,18)  );
    BnOk.setPreferredSize( BnEsc.getPreferredSize() );


	JPanel pnButton = new JPanel();
	//pnButton.setBackground(Color.red);
	pnButton.setLayout( new FlowLayout() );
	pnButton.add(BnOk);
	pnButton.add(BnEsc);

    this.getContentPane().add( pnButton, BorderLayout.SOUTH );

     // Beide Listener zeigen auf die gleiche Methode
     // Wie unterscheidet man die Aufrufe?
    BnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              Bn_Click(e);
            }
          });


    BnEsc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              Bn_Click(e);
            }
          });


  } // setGUI

    private void Bn_Click(ActionEvent e) {
        if (e.getSource()==BnOk)
          System.out.println("Hier BnOk");
        if (e.getSource()==BnEsc)
          System.out.println("Hier BnEsc");
    }



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

}  // Action5
