Menus, Dialogs and the Notepad App
Site Admin
· 11 Sep 2026
· 1 views
Menus
Menus need a MenuBar attached to the Frame, containing Menu objects with MenuItems:
MenuBar bar = new MenuBar();
Menu file = new Menu("File");
file.add(new MenuItem("New"));
file.add(new MenuItem("Open"));
file.add(new MenuItem("Exit"));
bar.add(file);
setMenuBar(bar);
Menus can nest (sub-menus) and items fire ActionEvent just like buttons.


File and Print Dialogs
FileDialog opens native open/save dialogs without extra code:
FileDialog fd = new FileDialog(this, "Open", FileDialog.LOAD);
fd.setVisible(true);
String file = fd.getFile();

Edit Operations
A TextArea supports clipboard operations directly with cut(), copy() and paste(), which are wired into a File/Edit menu.

The Notepad Demo
Combining a menu bar, file dialog and text area builds a small Notepad editor - open a file into the TextArea, edit it, and save it back.

Key Points
- MenuBar > Menu > MenuItem is the menu structure.
- FileDialog gives native open/save without extra code.
- cut(), copy() and paste() make an editor trivial to build.