Results 1 to 5 of 5
- 02-06-2011, 07:41 AM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Why declaring Swing variables in longform
I initially learnt how to design GUIs directly as source code. Now we (I am a student) are supposed to start using an interface to speed up the process. However, when I go into the source code I notice that the tool is generating longer code that I would have by hand. (I am using Netbeans)
For example it generates this:
Java Code:private javax.swing.JTextField topFieldText;
Whereas I would ordinarily just do this:
Java Code:private JTextField topFieldText;
I know this is probably a nuisance question but I would appreciate a response that explains why it does this. Which one of the two is best practice?
Many thanks in advance to those who will respond.Last edited by africanhacker; 02-06-2011 at 08:45 AM.
- 02-06-2011, 09:16 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Personally I wouldn't use the long winded form which I regard as far less readable. Sometimes the uneditable code in NB doesn't give you any choice in the matter.
If you post code here, many will not bother to read screenfuls of NB generated code and will expect you to construct a small example by hand (the way you are used to).
- 02-06-2011, 09:23 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Note that NetBeans can't safely generate the short form of those class names because the user might have used those class names for his/her own program; two different classes with the same (unqualified) name yields uncompilable code.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-06-2011, 09:30 AM #4
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Thanks guys, very speedy response. I would imagine that the clever people at Sun would have created an option for you to drop this needless code and take the risk of clashing classes, given that one would obviously be conscious of this possibility.
All the same, thank you for the explanation.
- 02-06-2011, 09:35 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
What are Instance variables and static variables?
By sandeshforu in forum New To JavaReplies: 3Last Post: 09-09-2009, 05:48 PM -
Declaring variables
By Flashmatix in forum New To JavaReplies: 12Last Post: 01-20-2009, 03:43 PM -
Declaring a Queue
By rhm54 in forum New To JavaReplies: 1Last Post: 03-21-2008, 05:02 AM -
Declaring an ArrayList
By bugger in forum New To JavaReplies: 3Last Post: 01-31-2008, 07:36 PM -
Declaring global variables
By eva in forum New To JavaReplies: 3Last Post: 12-23-2007, 12:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks