import java.applet.*;
import java.awt.*;

public class dialog extends Applet

{
 Frame window = new dmoframe("This is the first frame.");

 public void init()
  {
   window.show();
   add(new Label("Hit this button to"));
   add(new Button("Create another Frame"));
  }

 public boolean action(Event evt, Object whatAction)
  {
    if((evt.target instanceof Button))
     { 
	String buttonLabel = (String) whatAction;
	if (buttonLabel == "Create another Frame")
	 {
          Frame window = new dmoframe("This is another frame.");
          window.show();
	 }
     }
     return false;
  }
}
class dmoframe extends Frame
{
 dmoframe(String title)
 {
  super(title); 
  MenuBar topbar = new MenuBar();
  setLayout(new FlowLayout());
  setMenuBar(topbar);
  Menu fileMenu = new Menu("File");
  topbar.add(fileMenu);
  fileMenu.add("Quit");   
  add(new Label("Use the File menu to close this Window."));
  resize(300,100);
 } 
 public boolean action(Event evt, Object whatAction)
  {
    if (evt.target instanceof MenuItem)
     {
      if ((String)whatAction == "Quit")
       {
	Dialog dilog = new demodialog(this,"You hit Quit!",true); 
	dilog.show();
  	hide();
        dispose();
        return true;
       }
     }
    return false;
   } 
public boolean handleEvent(Event evt)
  {
    if (evt.id == Event.WINDOW_DESTROY)
     {
  	hide();
        dispose();
	return true;
     }
    return super.handleEvent(evt);
  } 
}
class demodialog extends Dialog
{
demodialog(Frame demoframe,String title,boolean yesno)
{
  super(demoframe,title,yesno);
  setLayout(new FlowLayout());
  add(new Label("hit OK to Continue"));
  add(new Button("OK"));
  resize(200,100);
}
 public boolean action(Event evt, Object whatAction)
  {
    if (evt.target instanceof Button)
     {
      String buttonLabel = (String) whatAction;
      if (buttonLabel == "OK")
       {
	hide();        
	dispose();
        return true;
       }
     }
    return false;
  } 
}
