0

Hello,

I am having some trouble with getting my menu to respond to a mouse click.I have 2 items on my menu, "New" and "Exit", and they are using the actionlistner like so

newFromMenu = new JMenuItem("New Screen");
newFromMenu.addActionListener(this);

and then my action event

public void actionPerformed(ActionEvent e){

if(e.getSource() == newFromMenu ){
			
showPictures.setEnabled(true);
			
b1.setSelected(false);
b2.setSelected(false);

			
resetPanel();
			
panel = createPane();
setContentPane(mainPanel);
		
setVisible(true);
}
}

The code compiles fine, but when I try to run the program I am presented with an error and the Frame will not display.Is it obvious as to what I am doing wrong?

Thanks
Static.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by StaticX
0

It was a null to pointer error. I have overcome the error through creating local actionPerformed event handlers instead of the method shown above and it now works.I think it may have been a problem with a JMenu Item having the same functionality as a button in the JFrame.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.