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.
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