• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Structural question

 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When building applications with swing, is it considered bad to make the components class variables? It's difficult to access them otherwise without making it very difficult to add more components.
I'd like to make my JTextAreas private class variables, but is that "bad" coding?
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used such type of code..with private JTextFields and JLabels etc.
I dont see any reason why it could be bad code..
:roll:
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's perfectly fine to ise member variables to hold references to components; in fact, there isn't realy any alternative. But you said class variables, or "static" variables in Java. This is not especially good style; it leads to code like this:



This is bad because it's procedural, because it makes the code hard to reuse, because it leads to very long, hard to modify methods, etc.

There's an easy alternative, and it looks like this:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic