Anthony Scaife
Anthony Scaife

Reputation: 564

Java, Netbeans and separation of concerns

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.

Upvotes: 1

Views: 174

Answers (2)

Code-Apprentice
Code-Apprentice

Reputation: 83577

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

Upvotes: 3

MadProgrammer
MadProgrammer

Reputation: 347334

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

Upvotes: 3

Related Questions