import java.applet.Applet;
import java.awt.*;

public class DialogFix extends Applet {
  private Button _mainButton;
  private TextField _labelTextField;
  private DialogFixDialog _dialog;

  public void init() {
    setLayout(new BorderLayout()); 

    _mainButton = new Button("Click Here For Dialog Window");
    add("Center", _mainButton);

    _labelTextField = new TextField("Dialog Message Should Appear Here");    
    add("South", _labelTextField);

  }

  public boolean handleEvent (Event event) {
    if (event.target == _mainButton && event.id == Event.ACTION_EVENT) {
        _dialog = new DialogFixDialog(getFrame(), true, this);
        _dialog.show();
        return true;
    }
    return super.handleEvent(event);
  }

  // This is the callback
  public void setResultTextField (String result) {
    System.out.println(result);
    _labelTextField.setText(result);
  }

  private Frame getFrame() {
    Container c = getParent();
    while (c != null && !(c instanceof Frame)) {
      c = c.getParent();
    }
    return (Frame)c;
  }

}