actionlistener returning a nullexception on jbutton
I have an action listener set up on my main jframe menu for the buttons listed on it, and they work fine, bringing up other jframes as needed. The problem is when a person clicks the buttons on the jframes brought up I get a nullexception after a jbutton is clicked on that submenu jframe.
Example code:
public class main extends JFrame implements ActionListener
{
public main
{
private JButton thisButton = new JButton( "this" );
private JButton thatButton = new JButton( "that" );
thisButton.addActionListener( this );
thatButton.addActionListener( this );
thisButton.setActionCommand( "THISBUTTON" );
thatButton.setActionCommand( "THATBUTTON" );
setLayOut( new FlowLayout() );
add(thisButton);
public void actionPerformed( ActionEvent event )
{
String source = event.getActionCommand();
if( source.equals( "THISBUTTON" )
{
JFrame thisFrame = new JFrame();
thisFrame.add( thatButton );
if( source.equals( "THATBUTTON" )
{
System.out.println( "pushed thatbutton" );
}
}
}
}
}
Now I am almost certain that I need to set up another action listener for the inner jbutton but I开发者_如何学编程 am at a lost to how to do that.
To set up another action listener for the inner JButtons just write this code for each button
thisButton.addActionListener(this);
精彩评论