views:

7

answers:

0

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.