• 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

Swing Components Declared in an Interface

 
Ranch Hand
Posts: 85
Mac Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys; I have trolled this forum a bunch. Love it. First time posting though.
I have an interface that I am using for some Frames that I am using. I declare the components (Jbuttons, Jlabels etc) in the interface. Works great for the first Class that implements the interface; however the 2nd class that implements the interface retains the values of the first class assigned to the components. (And vice versa depending on which class is called first). I am coming to understand that variables and components declared in an interface are really one entity and not a fresh copy each time you implement the interface.
Would it be better then to just have a container class that stores the components and instantiate that for the components? And then keep the interface for my abstract methods.

Just want to make sure I am thinking about this right and implementing the correct solution.

Thanks again.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the Java Language Specification

Every field declaration in the body of an interface is implicitly public, static, and final.



If you have a lot of GUI classes that share some commonality, you could design that common portion as a separate class and incorporate an instance of that class in each separate GUI (favor composition over inheritance).
 
Cory Hartford
Ranch Hand
Posts: 85
Mac Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will do. Thanks Darryl.
 
reply
    Bookmark Topic Watch Topic
  • New Topic