Results 1 to 11 of 11
Thread: Hello Family
- 12-09-2010, 10:18 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
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.
Any suggestions guys?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
I would really appreciate it! :)
Kind regards
Shyam
- 12-09-2010, 10:54 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Does that compile?
If it does not and you can't understand the compiler message, copy and post the entire message here.
- 12-09-2010, 10:57 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
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
- 12-09-2010, 11:00 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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.
- 12-09-2010, 11:10 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
I don't seem to understand. Could you show me where i went wrong. that would most helpful.
Thankyou so much!
- 12-09-2010, 11:19 PM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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!
- 12-09-2010, 11:46 PM #7
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
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
- 12-10-2010, 01:16 AM #8
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Now remember your promise. :)Java Code:public HelloFamily([COLOR="Blue"]int[/COLOR] noOfColumns, [COLOR="Blue"]int[/COLOR] noOfRows)
-Gary-
-
- 12-10-2010, 02:04 AM #10
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
- 12-10-2010, 10:11 AM #11
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
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
-
Aspose.Total Product Family Q3 2010 Released
By sherazam in forum Java SoftwareReplies: 0Last Post: 10-04-2010, 01:48 PM -
Set Font Color, Font Style & Font Family While Replacing Text
By sherazam in forum Java SoftwareReplies: 0Last Post: 08-18-2010, 10:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks