Results 1 to 5 of 5
  1. #1
    int80 is offline Member
    Join Date
    Jul 2008
    Posts
    29
    Rep Power
    0

    Default Creating an Array of Objects

    I'm trying to create an array of groups, so I can reference them like this

    Java Code:
    group[0].setText("Whatever");
    group[1].setTex("Java");
    This is what I've done so far, and I know it's wrong.

    Java Code:
    		
                    final Group[] group = new Group[2];
    		group[0] = new Group(shell, SWT.SHADOW_IN);
    		group[0].setText("Bikes");
    		group[0].setLocation(12, 12);
    		
    		group[1] = new Group(shell, SWT.SHADOW_IN);
    		group[1].setText("Controls");
    		group[1].setBounds(190, 12, 0, 124);
    		
    		group[2] = new Group(shell, SWT.SHADOW_IN);
    		group[2].setBounds(304, 12, 176, 128);
    		group[2].setText("Order");
    I reckon this bit's the wrong bit: group[0] = new Group(shell, SWT.SHADOW_IN);

    It's just how to I associate the group with shell?

    thanks in advance!

  2. #2
    int80 is offline Member
    Join Date
    Jul 2008
    Posts
    29
    Rep Power
    0

    Default

    Oh, and I get this error message:

    Java Code:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    	at classic.uni.main(uni.java:30)
    Line 30 being this line:

    Java Code:
    		group[2] = new Group(shell, SWT.SHADOW_IN);

  3. #3
    int80 is offline Member
    Join Date
    Jul 2008
    Posts
    29
    Rep Power
    0

    Default

    I solved it, it was a moronic mistake not understanding how to make arrays in Java properly....

  4. #4
    lkalaivanan is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default Same problem

    Me having the same problem, Send your corrected codes

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by lkalaivanan View Post
    Me having the same problem, Send your corrected codes
    Please don't command the OP to do anything; b.t.w. this thread is three years old; start your own thread if you want to but don't resurrect old zombies ...

    kind regards,

    Jos

    ps. thread closed
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Creating objects based on a String value
    By lvh in forum New To Java
    Replies: 4
    Last Post: 04-30-2008, 02:00 PM
  2. Creating an array of nonprimitive objects
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:46 PM
  3. Array of Objects
    By bluefloyd8 in forum New To Java
    Replies: 5
    Last Post: 01-22-2008, 07:27 PM
  4. Creating objects question
    By sergm in forum New To Java
    Replies: 2
    Last Post: 12-27-2007, 05:10 PM
  5. array of objects
    By Jack in forum New To Java
    Replies: 2
    Last Post: 07-02-2007, 05:24 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
  •