Having trouble with the GUI?
Oct. 30, 2009
Some of you have complained about getting a Null Pointer Exception when trying to set a color on a "brush," like this:
Graphics brush = pnlSimulation.getGraphics();
brush.setColor(Color.BLUE);
That second statement will generate an error if you attempted to execute it before pnlSimulation is displayable. To correct the error, make sure that:
- pnlSimulation is added to the content pane -- for example, with c.add(pnlSimulation, BorderLayout.CENTER())
- the window is visible -- with this.setVisible(true);