import java.applet.*;
import java.awt.*;
import java.lang.*;
import java.util.*;
public class MenubarApplet extends Applet {
private Frame frame;
private MenuBar mb;
private Menu fm, hm;
private MenuItem ol, of, pr, hi, hc;
private Label message =
new Label("Select an option from a menu (nothing will happen)");
public void init() {
setLayout(new BorderLayout());
add("Center",message);
Object f = getParent ();
while (! (f instanceof Frame))
f = ((Component) f).getParent ();
frame = (Frame) f;
mb = new MenuBar();
mb.add(fm = new Menu("File"));
mb.add(hm = new Menu("Help"));
mb.setHelpMenu(hm);
fm.add(ol = new MenuItem("Open Location"));
fm.add(of = new MenuItem("Open File"));
fm.addSeparator();
fm.add(pr = new MenuItem("Print"));
hm.add(hi = new MenuItem("Index"));
hm.add(hc = new MenuItem("Content"));
frame.setMenuBar(mb);
frame.pack();
}
public boolean action(Event e, Object arg) {
if (e.target == ol || e.target == of || e.target == pr ||
e.target == hi || e.target == hc) {
message.setText((String) arg);
return true;
}
return super.action(e,arg);
}
}
|