|
|
#1 (permalink) |
|
500+ Posts????
|
Okay, Ive been up for way too long and don't feel like staring more at this code trying to figure out why its not compiling correctly for me. So, anyone care to see why Im getting these errors:
Code:
init:
deps-jar:
compile-single:
run-single:
Exception in thread "main" java.lang.NullPointerException
at JNotePad.MenuBar.createFileMenu(MenuBar.java:84)
at JNotePad.MenuBar.<init>(MenuBar.java:15)
at JNotePad.MenuBar.main(MenuBar.java:104)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MenuBar extends JFrame
{
private JMenuBar menubar;
public MenuBar()
{
setTitle("Test");
createFileMenu();
// createEditMenu();
// createHelpMenu();
setJMenuBar(menubar);
setSize(400,400);
setVisible(true);
}
private void createFileMenu()
{
JMenu menu = new JMenu("File"); // Create File menu.
menu.setMnemonic(KeyEvent.VK_F); // Underlined F
JMenuItem menuItem = new JMenuItem("Save", null);
menuItem.setMnemonic(KeyEvent.VK_S); // Underline S
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showDialog("Are you sure you want to save?", "Save?",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Save As...", null);
menuItem.setMnemonic(KeyEvent.VK_A);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showDialog("Are you sure you wish to save all?", "Save All",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
}
});
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Delete", null);
menuItem.setMnemonic(KeyEvent.VK_D);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showDialog("Are you sure you want to delete? Information cant be recovered!", "Delete?",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
}
});
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Exit", null);
menuItem.setMnemonic(KeyEvent.VK_X);
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showDialog("Are you sure you want to exit?", "Exit",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
}
});
menu.add(menuItem);
menubar.add(menu);
}
/*
private void createEditMenu()
{
}
private void createHelpMenu()
{
}
*/
public void showDialog(String message, String title, int option, int icon)
{
JOptionPane.showInternalConfirmDialog(null, message, title, option, icon);
}
public static void main(String[] args)
{
MenuBar mb = new MenuBar();
mb.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
|
|
|
|
|
#3 (permalink) |
|
500+ Posts????
|
Eh, I knew lack of sleep would kill me. I just changed:
Code:
private JMenuBar menubar; Code:
private JMenuBar menubar = new JMenuBar(); Glad Im not doing anything at work today. Thanks
|
|
|
|
|
#4 (permalink) |
|
Orc's Breathmint
|
yes.. this is correct, i found that out myself
__________________
.::::::What dosent kill you, makes you stronger::::::.
Go to my freaking web site renamation.tripod.com/ga ![]() ![]() |
|
|
| Thread Tools | |
| Display Modes | |
|
|