You need to instantiate panel
before adding it. If you use panel before calling MyPanel()
, panel
is still null
, hence the NullPointerException
.
While you're here, give this a glance. http://geosoft.no/development/javastyle.html
Method names in Java should be mixed case starting with a lower case letter, e.g. myPanel()
instead of MyPanel()
. To most of us, MyPanel()
looks like a constructor at first glance because you improperly styled it.
Additionally, MyPanel
, Text
, Fields
, and Buttons
should all be private methods, as it would be improper for an external class to call them.