1

I am new to Java and Netbeans, and want to write a Swing project to learn by.

Naturally I want to separate the "guts" of the code from the GUI class. How should I go about it, best practice ?

Should I:

  1. Use public static void main(String[] args) in the GUI class. Then create an instance of a "controller". Calling controller functions via GUI events (passing only data) ?
  2. Use public static void main(String[] args) in the "controller", and pass an instance of the controller to the GUI class ?

Create instances, or use classes statically ? And what of this invokeLater business ?

[ some little code samples would be lovely ]

Thanks. Anthony.

Anthony Scaife
  • 564
  • 5
  • 15
  • http://www.oracle.com/technetwork/articles/javase/index-142890.html and http://stackoverflow.com/questions/14219737/programming-with-a-java-mvc-approach-using-netbeans-gui-builder – yǝsʞǝla Jan 20 '14 at 01:02

2 Answers2

3

Three: Put main() in its own class and intitialize all objects as needed.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
3

I'd create a Main class or other entry class that contains main. This would be responsible for preparing the system, initialising common library elements and general house keeping.

As to which element needs to be "started" will depend on the structure of your code and your implementation of the MCV

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366