• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this a Coding Style question ???

 
Alan A Smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my GUI design, a ConfigWindow class is used to select the connection type, it extends JFrame.
I want to click the JButton to enable/disable the textfield.

I should declare to textfield outside the method or declare inside the method as a final???
Which method I should use??
Thx. a lot
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the class is a JFrame, it think it is better to declare it as a member variable of the class, and not within the method.
Mark
 
Alan A Smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx for reply. But I have one more question. How about the JButton in my code. To be consistent, I should also declare it as class variable not the method variable??
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I basically made all the elements on the GUI be instance variables.
Mark
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!