| Food for thought: How can we add a menu bar to our Frame? |
|
import accounting.*;
import java.awt.*;
class Accounting extends Frame {
StockAccount account;
static final String NAME = "Accounting";
public Accounting() {
super(NAME);
account = new StockAccount(NAME);
try {
account.readFromFile();
} catch (Exception e) {
System.err.println(e + " could not read from file");
}
setLocation(new Point(30, 30));
DisplayCanvas canvas = new DisplayCanvas(account);
add(canvas);
Menu file = new Menu("File", true);
MenuItem quit = new MenuItem("Quit");
file.add(quit);
MenuBar mb = new MenuBar();
mb.add(file);
setMenuBar(mb);
pack();
}
public static void main(String[] args) {
Accounting a = new Accounting();
a.setVisible(true);
}
}
|
Note: We examine how to handle events caused by clicking on a menu item in the next lesson.
|
Dan Keller Technical Services 4500 19th St., San Francisco California, USA 94114 tel: 415 / 861-4500 |