I'm using the class ProgramMenuBar to make a Menu Bar that has print and will actually print.
However, while the options are there, they throw Null Pointer Exceptions when selected.
I have a big program I'm using, but you guys always want something smaller, so:
import java.awt.color.ColorSpace; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.AdjustmentEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; import javax.swing.text.DefaultStyledDocument; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.ScrollPaneConstants; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.io.*; import javax.swing.ImageIcon; import java.awt.event.WindowEvent; import java.awt.Window; import javax.swing.JScrollPane; import java.awt.Component; import javax.swing.JMenu; import javax.swing.JMenuItem; import acm.io.*; import acm.graphics.*; import acm.program.*; import acm.gui.*; import acm.util.*; import java.awt.Container; public class sampleClass extends JFrame { JPanel panel; JMenu menu; ProgramMenuBar bar; public sampleClass() { setTitle("Title"); panel = new JPanel(); bar = new ProgramMenuBar(); menu = new JMenu(); panel.add(bar); bar.add(menu); bar.setVisible(true); panel.setVisible(true); menu.setVisible(true); bar.addFileMenu(); bar.addFileMenuItems(menu); bar.addEditMenu(); bar.addEditMenuItems(menu); bar.init(); getContentPane.add(panel); } public static void main(String[] args) { sampleClass referenceVariable = new sampleClass(); referenceVariable.showGUI(); } public void showGUI(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300,300); setLocation(100,100); setVisible(true); } }
How do I get the parts of the menu to work?