• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI confusion

 
Kendall Clanton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a question in regards to GUI programming in Java. I have been looking at a variety of GUI source codes and I am confused. I have noticed that some examples show the GUI code before the "main" method while others show them after the "main" method. Could somebody please explain to me the reason for this as well as the preferred approach for programming a GUI?

 
Stevens Miller
Bartender
Posts: 1422
29
C++ Java Netbeans IDE Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

It really doesn't make any difference. Older languages need a routine defined (or, least, its signature declared) before it is called, as you work your way down from the top of a source file to its bottom. But Java doesn't care where, within a class definition, the various methods are defined.

I use NetBeans for most of my Java work. It tends to put the GUI code above the main method, in classes that have a main method. But you can put it wherever you want.

A better rule of thumb might be that, if your classes are getting so long that its hard to find the main method (or any particular method), then you might want to think about breaking those big classes up into additional smaller ones.
 
Kendall Clanton
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:Welcome to the Ranch.

It really doesn't make any difference. Older languages need a routine defined (or, least, its signature declared) before it is called, as you work your way down from the top of a source file to its bottom. But Java doesn't care where, within a class definition, the various methods are defined.

I use NetBeans for most of my Java work. It tends to put the GUI code above the main method, in classes that have a main method. But you can put it wherever you want.

A better rule of thumb might be that, if your classes are getting so long that its hard to find the main method (or any particular method), then you might want to think about breaking those big classes up into additional smaller ones.


Thank you for the response Stevens Miller.

I appreciate your answer as it greatly helped my understanding. This is only my first of soon to be many questions here on the Ranch.

Thank you once again for the help.
 
Stevens Miller
Bartender
Posts: 1422
29
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad we could help. More questions are always graciously received. Posting answers to the questions of others, when you can, is also much appreciated.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!