import java.applet.*; import java.awt.*; public class frames2 extends Applet { Frame window = new demoframe("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 demoframe("This is another frame."); window.show(); } } return false; } } class demoframe extends Frame { demoframe(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") { 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); } }