//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 "einer" onClick-Methode


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


// implements ActionListener erwartet die Methode actionPerformed
// wird zentral von allen Schaltern, Menues aufgerufen

public class Action8 extends JFrame implements ActionListener {

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

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

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

    BnOk.setActionCommand("Ok");
    BnEsc.setActionCommand("Esc");
    BnEsc.addActionListener(this);

    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 );

   // einfuegen der gloablen ActionPerformed Methode in die Listener
   // Wie unterscheidet man die Aufrufe?
   BnOk.addActionListener(this);
   BnEsc.addActionListener(this);

  } // setGUI

  public void actionPerformed(ActionEvent e) {
     System.out.println("Hier actionPerformed");
     String cmd = e.getActionCommand();
     if (cmd.equals("Ok") ) {
          System.out.println("Hier BnOk");
     }     
     if (cmd.equals("Esc") ) {
          System.out.println("Hier in BnEsc");
     }     
  }



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

}  // Action6
