/** * Method declaration * * @param s */ private void addToRecent(String s) { for (int i = 0; i < iMaxRecent; i++) { if (s.equals(sRecent[i])) { return; } } if (sRecent[iRecent] != null) { mRecent.remove(iRecent); } sRecent[iRecent] = s; if (s.length() > 43) { s = s.substring(0, 40) + "..."; } MenuItem item = new MenuItem(s); item.setActionCommand("#" + iRecent); item.addActionListener(this); mRecent.insert(item, iRecent); iRecent = (iRecent + 1) % iMaxRecent; }
public static void startApplet( Applet applet, String title, Hashtable params, int width, int height) { applet1 = applet; // setup so as getParameter, etc, will work OurAppletContext newAppletContext = new OurAppletContext(applet.getToolkit()); OurAppletStub newAppletStub = new OurAppletStub(newAppletContext, params); applet.setStub(newAppletStub); // create new application frame window AppletFrame f = new AppletFrame(title + extraTitle); // add applet to frame window f.add("Center", applet); // add a quit menu item MenuBar menubar = new MenuBar(); Menu file = new Menu("File", true); MenuItem item = new MenuItem("Quit"); menubar.add(file); file.add(item); f.setMenuBar(menubar); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // At this point, we simply leave. java.lang.Runtime.getRuntime().exit(0); } }); // resize frame window to fit applet f.pack(); f.setSize(width, height); applet.setSize(width, height); // initialize the applet applet.init(); applet.start(); // show the window f.show(); f.repaint(); } // end startApplet()
/** * Method declaration * * @param f * @param m */ void addMenuItems(Menu f, String m[]) { for (int i = 0; i < m.length; i++) { MenuItem item = new MenuItem(m[i].substring(1)); char c = m[i].charAt(0); if (c != '-') { item.setShortcut(new MenuShortcut(c)); } item.addActionListener(this); f.add(item); } }