
import java.awt.*;
import java.awt.event.*;

/** Einfacher Dialog im Messagebox-Style mit OK-Button */
public class MessageBox extends Frame {

 /** Constructor, nimmt Titel und Ausgabestring entgegen 
   * @param String Titel der MessageBox
   * @param String Ausgabestring der Messagebox 
   */
 MessageBox (String Title, String InfoText) {
    super (Title); // Fenster mit Titel title erzeugen

   // Action-Listener für Button definieren
    class OKButtonListener implements ActionListener {
      // Event-Handler für Komponenten-Events
       public void actionPerformed( ActionEvent e ) {
          if (e.getActionCommand().equals("OK")) { // OK-Button gedrückt
             setVisible (false); // Dialog verschwinden lassen...
             dispose(); // ...und killen
          }
       } 
    }
    OKButtonListener globalListener = new OKButtonListener();
    
   // Window-Listener für Schließen-Button definieren
    WindowListener exitListener = new WindowAdapter()
    {
      // Event-Methode die beim Schließen aufgerufen wird
       public void windowClosing (WindowEvent ThisEvent) {
          setVisible (false); // Dialog verschwinden lassen...
          dispose(); // ...und killen
       }
    };
    addWindowListener(exitListener); // Event-Handling aktiv.

   // InfoText-Label und Button plazieren
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints constr = new GridBagConstraints();
    constr.fill = GridBagConstraints.BOTH;
    setLayout (layout);

   // InfoText-Label und Leerzeilen plazieren
    constr.gridwidth=GridBagConstraints.REMAINDER;  
    Label titleLabel = new Label (" ", Label.CENTER);
    layout.setConstraints (titleLabel, constr);
    add (titleLabel);
    titleLabel = new Label (InfoText, Label.CENTER);
    layout.setConstraints (titleLabel, constr);
    add (titleLabel);
    titleLabel = new Label (" ", Label.CENTER);
    layout.setConstraints (titleLabel, constr);
    add (titleLabel);

   // Plot-Button plazieren:
    constr.gridwidth=1;  constr.weightx=1.0;
    titleLabel = new Label (" ", Label.CENTER);
    layout.setConstraints (titleLabel, constr);
    add (titleLabel);     
    Button plotButton = new Button ("OK"); 
    plotButton.addActionListener (globalListener); 
    layout.setConstraints (plotButton, constr);
    add (plotButton);    
    constr.gridwidth=GridBagConstraints.REMAINDER;
    titleLabel = new Label (" ", Label.CENTER);
    layout.setConstraints (titleLabel, constr);
    add (titleLabel);     
    titleLabel = new Label (" ", Label.CENTER);
    layout.setConstraints (titleLabel, constr);
    add (titleLabel);     


   // Komponenten "zusammenpacken" und Frame anzeigen
    pack();
    setSize (getPreferredSize());
    show();
 }

}