// // FrameDemo class // part of the set of documents known as Java no sugar. // Copyright (c) 1996 Sunil Gupta, sunil@magnetic.demon.co.uk // placed into the public domain by the author // import java.awt.*; import java.applet.*; import SimpleFrame; public class FrameDemo extends Applet { //******************************************************************* // globals //******************************************************************* static final String DIALOG = "DIALOG"; static final String FRAME = "FRAME"; static final String MENUBAR = "MENUBAR"; static final String MENUITEMS = "MENUITEMS"; static final String CHECKMENU = "CHECKMENU"; //******************************************************************* // instance variables //******************************************************************* Button btn_frame, btn_dialog, btn_menubar, btn_menuitem, btn_checkmenu; //******************************************************************* // applet methods //******************************************************************* public void init() { String style; style = getParameter("STYLE"); if (style == null) System.exit(1); else { this.setLayout( new FlowLayout()); if (style.equals(FRAME)) { btn_frame = new Button("click on me to get a frame"); this.add(btn_frame); } else if (style.equals(DIALOG)) { btn_dialog = new Button("click on me to get a dialog"); this.add(btn_dialog); } else if (style.equals(MENUBAR)) { btn_menubar = new Button("Show me a frame with a menubar"); this.add(btn_menubar); } else if (style.equals(MENUITEMS)) { btn_menuitem = new Button("show me a frame with menuitems"); this.add(btn_menuitem); } else if (style.equals(CHECKMENU)) { btn_checkmenu = new Button("show me checked menu items"); this.add(btn_checkmenu); } } } public boolean action(Event event, Object arg) { Frame frame; if (event.target == btn_frame) { frame = new SimpleFrame("example frame"); frame.pack(); frame.show(); return (true); } if (event.target == btn_dialog) { frame = new SimpleFrame("dialog from a frame", SimpleFrame.DIALOG); frame.pack(); frame.show(); return (true); } if (event.target == btn_menubar) { frame = new SimpleFrame("example frame with menubar", SimpleFrame.MENUBAR); frame.pack(); frame.show(); return (true); } if (event.target == btn_menuitem) { frame = new SimpleFrame("example menuitems", SimpleFrame.MENUITEMS); frame.pack(); frame.show(); return (true); } if (event.target == btn_checkmenu) { frame = new SimpleFrame("example checked menu items",SimpleFrame.CHECKMENU); frame.pack(); frame.show(); return (true); } return(false); } }
.