Current Position:Home > Re-Using Objects

Re-Using Objects

Update:11-30Source: network consolidation
Could someone explain if re-using the same object to create multiple instances of the object (say a JTextField) is better than defining a whole new object for each instance.JTextField tf;
public void createFields() {
  tf = new JTextField(20);
  JPanel p = new JPanel();
  tf = new JTextField(20);
  contentPane.add(p, BorderLayout.CENTER ); // Just for explanation purposes.
} Is this a better way to do things. as against JTextField tf, tf2;
public void createFields() {
  tf = new JTextField(20);
  JPanel p = new JPanel();
  tf2 = new JTextField(20);
  contentPane.add(p, BorderLayout.CENTER ); // Just for explanation purposes.
} I ask because,
1. how will you be able to identify a particular field when you need to get some piece of information?
2. Is this is a better way to utilize system resources?

The Best Answer

By the way I have another question.
It is advisable to be importing whole packages instead
of specific classes. I ask because I tend to do
this.import javax.swing.border.*;when in the whole class I might just use the
LineBorder or EmptyBorder. Does this also have some
effect on performance in terms of initial start up of
my application.?
ICENo, java only includes those classes which are necessary, doesn't make any difference in application. May be importing whole packages might slow down the compile time, nothing more than that.
  • Error while activating a routine  "no object list" Update:10-11

    hi I am getting a error while activating a routine Rv50c601 "There is no object list for INCLUDEs"  Please suggest on the error and resoulution regards NishantTry running program RV80HGEN. Regards, Naiimesh PatelRead other 3 answers

  • Error in VBA reference for Adobe Photoshop CS4 Object Library Update:10-11

    Hello, I'm using Windows 7 Pro, MS Office 2010 Pro and Creative Suite CS4 (with all updates). I will automate Photoshop via Visual Basic for Applications in MS Access. Befor using there the Adobe Photoshop CS4 Object Library I must reference it in VB

  • Logical Database in Abap Objects Update:10-11

    Hi to All I want do it a program report using a Logical Database. Is this possible ??? But when I make a GET <node>, occurs the following error:          "" Statement "ENDMETHOD" missing.  "" I'm doing the following: CL

  • Null and empty string not being the same in object? Update:10-11

    Hello, I know that null and empty string are interpreted the same in oracle. However I discovered the strange behaviour concerning user defined objects: create or replace TYPE object AS OBJECT ( value VARCHAR2(2000) declare xml xmltype; obj object; b

  • "cacheHostInfo is null" and Add-SPDistributedCacheServiceInstance : Object reference not set to an instance of an object. Update:10-11

    I am working on a standalone install Sharepoint 2013 (no Active Directory). I found newsfeed feature is not available and checked Distributed Cache service is stopped. When start it "cacheHostInfo is null" is returned. I checked the Windows serv

  • Open and Close Posting Periods According to G/L Account Assignment Objects Update:10-11

    Hi, Can anybody please explain me how configurations related to " Open and Close Posting Periods According to G/L Account Assignment Objects " works in SAP FICO? I am confused about this config. Regards, MandeepHi Mandeep , First i would like to

  • Two resultset objects Update:10-11

    IS it possible to define two resultset objects with two different queries inside the same DB class?java.sql.SQLException: Invalid state, the ResultSet object is closed.      at net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(

  • Open field in object S_TCODE Update:10-11

    I've deleted a tcode from a role in menu tab. Now when I look at the object S_TCODE in the role it has an open(blank) field. I cannot delete this blank field from the object as S_TCODE shows up only in display mode though you enter the role in change

  • Can't print OLE objects when 9i report developed in 6i Update:10-11

    Hi, I am migrating my reports from 6i to 9i. I just open report in 9i which is already developed in 6i and run the report it don't print OLE objects. It shows when I run report in Designer Preview, but in printing it shows blank --Vijay              

  • Questions on ADF View Objects, Links and Iterators Update:10-11

    I have a number of questions regarding using ViewObjects in applications where there are alot of relationships between tables. First, lets say that I have ViewObject SomeView that was added to the App Module (AM) as VO1. And because it has a number o