correct way of initializing variables

Posted by OVERTONE on Stack Overflow See other posts from Stack Overflow or by OVERTONE
Published on 2010-04-26T16:17:58Z Indexed on 2010/04/26 16:23 UTC
Read the original article Hit count: 206

Filed under:
|
|
|

ok this is just a shot in the dark but it may be the cause of most of the errors ive gotten.

when your initializing something. lets say a smal swing program. would it go liek this

variables here
{
  private Jlist contactList;
  String [] contactArray;
  ArrayList <String> contactArrayList;
  ResultSet namesList

constructor here

   public whatever()
{
    GridLayout aGrid = new GridLayout(2,2,10,10);

    contact1 =  new String();
    contact2 =  new String();
    contact3 =  new String();

    contactArrayList = new ArrayList<String>();

// is something supposed too go in the () of this JList?
   contactList = new JList();

   contactArray = new String[5];

   from1 =new JLabel ("From: " + contactArray[1]);



gridlayout.add(components)// theres too many components to write onto SO.

}

// methods here

public void fillContactsGui()
        {
           createConnection();
           ArrayList<String> contactsArrayList = new ArrayList<String>();




            while (namesList.next())
                   {
               contactArrayList.add(namesList.getString(1));

                               ContactArray[1] = namesList[1];

                                      }

} i know this is probably a huge beginner question but this is the code ive gotten used too. im initializing thigns three and fours times without meaning too because im not sure where they gp. can anyone shed some light on this?

p.s. sorry for the messy sample code. i done my best.

© Stack Overflow or respective owner

Related posts about java

Related posts about swing