Advanced Graphical User Interface Components


There are three steps to creating a menu:

  1. Create the MenuBar
  2. Create the Menus
  3. Create the MenuItems

A MenuBar is added to a frame.
A Menu is add to the MenuBar
A MenuItem is added to the Menu

public class JavaPad {

	private Frame frame = new Frame("JavaPad");
	private MenuBar menuBar = new MenuBar();
	private Menu fileMenu = new Menu("File");
	private MenuItem fileOpen = new MenuItem("Open");

	public JavaPad() {


File dialogs are used for setting the file name and path - nothing more.

	private FileDialog openFile = new FileDialog(frame, "Open File", FileDialog.LOAD);
	private FileDialog saveFile = new FileDialog(frame, "Save File", FileDialog.SAVE);;
	fileName = openFile.getFile();
	pathName = openFile.getDirectory();
If getFile() returns null, that means no file was selected.