• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Global Components/Good Programming Practice

 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have a program with a lot of JTextFields and JLabels, and they need to be accessed by all of the functions in a class. I've also learned that its bad programming practice to have a lot of global variables/components. So what's worse programming practice, making about 20 components global, or having your entire program in one long function? Or is there a way to avoid these problems?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12188
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if they need to be accessed by all the methods of the class, then you should make them member variables of the class:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic