 <p>As others have said it is likely that the displayBox variable is null.</p> <p>The best way to deal with this is at compile time... if you get into the following habit you will catch that sort of mistake early:</p> <pre><code>public class TestFrame extends JFrame { private final JButton aButton; private JButton bButton; public TestFrame() { // fails to compile since aButton is not instantiated // aButton = new JButton("A"); } public init() { add(aButton); add(bButton); aButton.addActionListener(....); // crash at runtime since bButton is null bButton.addActionListener(....); } } </code></pre> <p>by declaring variables as "final" the compiler forces you to give them a value. Since the buttons (and other GUI items) are not likely to change you should be able to make them all final. Once you have that you will have the com;iler help you out to avoid this sort of thing.</p>