//Titel:            Dialog-Fenster
//Version:
//Copyright:		Copyright (c) 2010
//Autor:
//Organisation:
//Beschreibung:


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


public class Key02 extends JFrame   {

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


  private JPanel jpanel;


  public Key02() {
    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() );

    this.getContentPane().setLayout( new BorderLayout() );
    jpanel = new JPanel();
    jpanel.setBackground(Color.red);
    this.getContentPane().add( new JScrollPane(jpanel), BorderLayout.CENTER);

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

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

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


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

         BnOk.addKeyListener(new KeyAdapter() {
                    public void keyReleased(KeyEvent e) {
                                  System.out.println("keyReleased");
                       if ( e.getID() == KeyEvent.KEY_TYPED) {
                          char c = e.getKeyChar();
                          System.out.println("key character = '" + c + "'");
                       } else {
                             int keyCode = e.getKeyCode();
                             String keyString = "key code = " + keyCode
                              + " ("
                                  + KeyEvent.getKeyText(keyCode)
                             + ")";
                              System.out.println(keyString);
                       }

                     }
		    public void keyPressed(KeyEvent evt) {
                              System.out.println("KeyPressed");
		        if(evt.getKeyCode()==KeyEvent.VK_ENTER) {
                            System.out.println("          Enter");
		        }		        
		    }
		});

  } // setGUI

    private void BnOk_Click() {
        System.out.println("Hier in Ok");
    }

    private void BnEsc_Click() {
        setVisible(false);
        System.exit(0);
    }







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

}  // Key01


