Results 1 to 11 of 11

Thread: Hello Family

  1. #1
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

    Default Hello Family

    Hey guys how are you all. I've created a program that displays my family's names in GUI. I decided now that i want to take it to the next level and have 2 command line arguments, the row and the column to display the names in a grid layout. I am not sure how to do this, i have converted the strings to Integers but don't know how to call them.

    Java Code:
    import java.awt.Container;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    
    // Program to display a greeting to family members.
    public class HelloFamily extends JFrame
    {
      // Constructor.
      public HelloFamily(noOfColumns, noOfRows)
      {
        setTitle("Hello Family");
        Container contents = getContentPane();
        
        // Family names to appear in one line.
        contents.setLayout(new GridLayout(0, noOfColumns, 10, 20));
        
        contents.add(new JLabel("Hello Shyam!"));
        contents.add(new JLabel("Hello Devesh!"));
        contents.add(new JLabel("Hello Dinesh!"));
        contents.add(new JLabel("Hello Ramila!"));
        contents.add(new JLabel("Hello Suresh!"));
        contents.add(new JLabel("Hello Vijya!"));
        contents.add(new JLabel("Hello Shashi!"));
        contents.add(new JLabel("Hello Manju!"));
        contents.add(new JLabel("Hello Premji!"));
        contents.add(new JLabel("Hello Kanta!"));
        contents.add(new JLabel("Hello Ronak!"));
        contents.add(new JLabel("Hello Rohini!"));
        contents.add(new JLabel("Hello Palvi!"));
        contents.add(new JLabel("Hello Jahanvi!"));
        
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
      } // HelloFamily
      
      // Create a HelloFamily and make it appear on screen.
      public static void main(String [] args)
      {
        int noOfColumns = Integer.parseInt(args[0]);
        int noOfRows = Integer.parseInt(args[1]);
        
        HelloFamily();
        
        HelloFamily theHelloFamily = new HelloFamily();
        theHelloFamily.setVisible(true);
      } // main
    } // class HelloFamily
    Any suggestions guys?

    I would really appreciate it! :)

    Kind regards

    Shyam

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Does that compile?

    If it does not and you can't understand the compiler message, copy and post the entire message here.

  3. #3
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

    Default

    It doesn't compile. It's because of how i've called it. I've not done it right.
    I'm not sure how to do it... Can you help me please.

    Java Code:
    HelloFamily.java:10: <identifier> expected
      public HelloFamily(noOfColumns, noOfRows)
                                    ^
    HelloFamily.java:10: <identifier> expected
      public HelloFamily(noOfColumns, noOfRows)
                                              ^
    2 errors

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    You are getting this message because of how you have written the constructor. The arguments of constructors (and methods) must mention the type (int, String, double, etc) as well as the variable.

  5. #5
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

    Default

    I don't seem to understand. Could you show me where i went wrong. that would most helpful.

    Thankyou so much!

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    This is fairly basic stuff, so you might benefit most from reading a good tutorial. Methods and constructors is covered in Defining Methods and Providing Constructors for Your Classes in Oracle's Tutorial. There is a lot of good explanatory material in the opening chapters of this tutorial.

    Post back if you have specific problems with these sections.

    Sorry if this isn't the response you are looking for. It is my genuine belief that this stuff is covered best in a tutorial because it is more comprehensive. Others may have a different attitude. Good luck!

  7. #7
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

    Default

    I just wanted the actual way to do it, then i look at the tutorial after to understand it. That's my learning method. Can you not show me what the correction would be please, if that's not too much trouble .

    Regards

    Shyam

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Java Code:
      public HelloFamily([COLOR="Blue"]int[/COLOR] noOfColumns, [COLOR="Blue"]int[/COLOR] noOfRows)
    Now remember your promise. :)

    -Gary-

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

    Default

    Quote Originally Posted by Shyamz1 View Post
    I just wanted the actual way to do it, then i look at the tutorial after to understand it. That's my learning method. Can you not show me what the correction would be please, if that's not too much trouble .
    You had better change your learning method fast, or you're going to learn very slowly. :rolleyes:

  10. #10
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by Shyamz1 View Post
    I just wanted the actual way to do it, then i look at the tutorial after to understand it. That's my learning method. Can you not show me what the correction would be please, if that's not too much trouble .

    Regards

    Shyam
    about as convincing as a politician at your door in Ireland :D

  11. #11
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

    Default

    Hey, i tried that, but then i get another error:

    HelloFamily.java:41: cannot find symbol
    symbol : constructor HelloFamily()
    location: class HelloFamily
    HelloFamily theHelloFamily = new HelloFamily();

    Sorry for being annoying :(

    I declared variables int noOfRows and int noOfColumns, and then obviously converted them using integer.parseInt in the main method

    Then i did what you said, public HelloFamily(int noOfColumns, int noOfRows)

    REgards

    Shyam

Similar Threads

  1. Aspose.Total Product Family Q3 2010 Released
    By sherazam in forum Java Software
    Replies: 0
    Last Post: 10-04-2010, 01:48 PM
  2. Replies: 0
    Last Post: 08-18-2010, 10:31 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
  •