I'm using documentation on sun.com to try and learn Java. I was trying a simple Notepad type program but cannot get the menus to display. I'm receiving no errors and cannot figure out what I've done wrong and/or left out.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NotepadInJava //implements ActionListener
{
//preparing container
JFrame notepadFrame;
JTextArea theTextArea;
JScrollPane scrollPane = new JScrollPane(theTextArea);
//File menu items
JMenu file;
JMenuItem open;
JMenuItem save;
JMenuItem exit;
//Edit menu items
JMenu edit;
JMenuItem copy;
JMenuItem cut;
JMenuItem selectAll;
JMenuItem paste;
public static void main(String[] args)
{
NotepadInJava app = new NotepadInJava();
}
public NotepadInJava()
{
notepadFrame = new JFrame();
notepadFrame.addWindowListener(null);
notepadFrame.setSize(600,600);
notepadFrame.setLocation(40,20);
notepadFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
notepadFrame.setVisible(true);
buildMenus();
}
private void buildMenus()
{
//create menu bar
JMenuBar MenuBar = new JMenuBar();
//notepadFrame.setJMenuBar(FileMenuBar);
//build File menu
file = new JMenu("File");
MenuBar.add(file);
//add Open to File menu
open = new JMenuItem("Open");
open.addActionListener(null);
MenuBar.add(open);
//add Save to File category
save = new JMenuItem("Save");
save.addActionListener(null);
MenuBar.add(save);
//add Exit to File category
exit = new JMenuItem("Exit");
exit.addActionListener(null);
MenuBar.add(exit);
//build Edit menu
edit = new JMenu("Edit");
MenuBar.add(edit);
//add Copy to Edit category
copy = new JMenuItem("Copy");
copy.addActionListener(null);
MenuBar.add(copy);
//add Cut to Edit category
cut = new JMenuItem("Cut");
cut.addActionListener(null);
MenuBar.add(cut);
//add Select All to Edit category
selectAll = new JMenuItem("Select All");
selectAll.addActionListener(null);
MenuBar.add(selectAll);
//add Paste to Edit category
paste = new JMenuItem("Paste");
paste.addActionListener(null);
MenuBar.add(paste);
}
}