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

// 1. Beispiel mit TextField und Schaltern



public class GUI_01 extends JFrame {

  JLabel jLabel1 = new JLabel();
  JTextField TName = new JTextField();

  JButton BnOk = new JButton();
  JButton BnESC = new JButton();

  public GUI_01() {
    setLocation(300,300);
    setSize(400, 200);
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  private void setGUI() {
    setTitle("1. Beispiel GUI");
    this.getContentPane().setLayout( new GridBagLayout() );

    jLabel1.setText("Name");
    TName.setText("");

    jLabel1.setFont( new Font("Arial", Font.BOLD,18)  );
    TName.setFont( new Font("Arial", Font.BOLD,18)  );

    BnOk.setText("Ok");
    BnESC.setText("Abbruch");
    BnOk.setFont( new Font("Arial", Font.BOLD,18)  );
    BnESC.setFont( new Font("Arial", Font.BOLD,18)  );

    BnOk.setPreferredSize( BnESC.getPreferredSize() );

    this.getContentPane().add(jLabel1,
         new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE,
            new Insets(0,25,40,0), 0, 0));

    this.getContentPane().add(TName,
        new GridBagConstraints(1, 0, 1, 1, 10000.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(0,25,40,25), 0, 0));


    JPanel pn = new JPanel();
    pn.add(BnOk);
    pn.add(BnESC);
//    pn.setBackground(Color.green);
    this.getContentPane().add(pn,
           new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(0,0,0,0), 0, 0));

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

    // Neue Version
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


  }


  private void BnOk_Click() {
    // Check Input, Leerzeichen an den Enden werden gelöscht
    String sRet = TName.getText().trim();
    if ( sRet.length()==0) {
      basis.Message("Eingabe","Bitte tragen Sie einen Wert ein");
      return;
    }
    // nun Aktion mit dem Text
  }

  private void BnESC_Click(){
      System.exit(0);
  }


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

}


class basis {
    /**
    * description: Zeigt eine Nachricht an   
    * @see Message, Yes-No, Yes-No-Esc, Ok-Esc
    *
    * @version     1.0  07.07.2002
    * @author      Michael Wilhelm HS Harz, FB AI
    * @param String sTitle, String sMessage
    * @return keinen
    * @exception keine
    */
  public static void Message( String sTitle, String sMessage) {
    JOptionPane.showConfirmDialog(null,sMessage,sTitle,
      JOptionPane.DEFAULT_OPTION,
      JOptionPane.INFORMATION_MESSAGE);  // Symbol
    /*  Optionen der Schalter:
         DEFAULT_OPTION    Ok
         YES_NO_OPTION
         YES_NO_CANCEL_OPTION
         OK_CANCEL_OPTION
     */
     /*  Symbole:
      ERROR_MESSAGE
      INFORMATION_MESSAGE
      WARNING_MESSAGE
      QUESTION_MESSAGE
      PLAIN_MESSAGE
     */

  } // Message


}
