Results 1 to 3 of 3

Thread: Some Questions

  1. #1
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default Some Questions

    I am trying to make a GUI that contains buttons, about 9 of them in (3X3).

    I want to use an array for the task but I am having problems...

    Please tell me why ...
    Java Code:
    JButton[] b;
    
    b[0] = new JButton();
    Would say it's no initialised????

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You must do two initializations here:
    1) Initialize the array
    2) Initialize the contents of the array, the items held within the array:

    Java Code:
    Fubar[] fubars = new Fubar[10]; // this initializes the array
    for (int i = 0; i < fubars.length; i++)
    {
      fubars[i] = new Fubar(); // this initializes the array items
    }
    Your code doesn't do point 1: it doesn't initialize the array first.

  3. #3
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

Similar Threads

  1. questions for 1yr exp
    By rahaman.athiq in forum Java Servlet
    Replies: 2
    Last Post: 11-26-2008, 01:13 AM
  2. I have Questions -_-
    By ChazZeromus in forum New To Java
    Replies: 5
    Last Post: 09-13-2008, 08:08 PM
  3. Questions About JSP?
    By mtz1406 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-19-2008, 07:56 PM
  4. questions
    By Gilgamesh in forum New To Java
    Replies: 3
    Last Post: 11-27-2007, 11:18 PM
  5. 3 Questions
    By hiranya in forum AWT / Swing
    Replies: 4
    Last Post: 11-14-2007, 04:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •