Do not place your data in the JPanel:
public static void main(String[] args) {
MyData oData = new MyData();
JFrame oJFrame = new JFrame();
oJFrame.getContentPane().add(new EnterDetails(oData));
oJFrame.setDefaultCloseOperation(oJFrame.EXIT_ON_CLOSE);
oJFrame.setSize(500, 500);
oJFrame.setVisible(true);
}
and please rip that main-function out of the JPanel. the main function belongs into a seperate class:
public class Application{
public static void main(String[] args) {
MyData oData = new MyData();
JFrame oJFrame = new JFrame();
oJFrame.getContentPane().add(new EnterDetails(oData));
oJFrame.setDefaultCloseOperation(oJFrame.EXIT_ON_CLOSE);
oJFrame.setSize(500, 500);
oJFrame.setVisible(true);
}
}
That class "Application" defines your application's lifecycle.
The GUI components are only for visual representation. You can create, change and destroy them whenever you need to.