• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GUI confusion

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic