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

public class DialogTest extends JFrame {
  
  public static void main(String[] args) {
    DialogTest w = new DialogTest();
    w.show();
  }

  private JTextArea d = new JTextArea();
  
  private JCheckBox cb = new JCheckBox("Modal Dialog?");

  public DialogTest() {
    setTitle("DialogTest");
    setSize(300,220);
    add("West",cb);
    add("East",new MakeButton());
    add("South",d);
  }

  private void makeDialog(boolean modalFlag) {
    final JDialog dialog = new JDialog(this,modalFlag);
    dialog.setSize(100,100);
    dialog.add("North",new CountButton(1));
    dialog.add("West",new CountButton(2));
    dialog.add("East",new CountButton(3));
    dialog.add("South", new ButtonAdapter("Hide") {
	  public void pressed() {
	    dialog.setVisible(false);
	  }
	});
    dialog.show();
  }

  private class MakeButton extends ButtonAdapter {

    public MakeButton() { 
      super("Make Dialog");
    }

    public void pressed() {
      makeDialog(cb.isSelected());
    }

  }

  private class CountButton extends ButtonAdapter {
    
    public CountButton(int value) {
      super("" + value);
    }
    
    public void pressed() {
      d.append("Button " + getLabel() + " pressed\n");
    }
  }
}

