Results 1 to 2 of 2

Thread: Hi.

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

    Default Hi.

    Hi guys, how are you all. I;m trying to print a timetable with 2 given command line arguments. the first command line is the times table e.g. 3 times table and the second is what it goes up to i.e. 10. they are both integer values.

    Java Code:
    import java.awt.Container;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    
    // Program to display a times table with 2 command line arguments.
    // First command line argument is the times table e.g. 3 times table.
    // Second command line is the value we want it to go up to.
    public class TimesTable extends JFrame
    {
      // Constructor.
      public TimesTable(int timesTable, 
                        int upTo, int answer)
      {
        setTitle("Times Table");
        Container contents = getContentPane();
        
        // Set layout to be a grid
        contents.setLayout(new GridLayout(0, 5, 10, 10));
        
        
        
        for (int i=1; i < timesTable; i++)
        {
          answer = (timesTable*i);
          contents.add(new JLabel(i));
          contents.add(new JLabel("X"));
          contents.add(new JLabel(timesTable));
          contents.add(new JLabel(answer));
        }
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
      } // TimesTable
      
      // Create a TimesTable and make it appear on screen.
      public static void main(String [] args)
      {
        int timesTable = Integer.parseInt(args[0]);
        int upTo = Integer.parseInt(args[1]);
        int answer;
        
        TimesTable theTimesTable = new TimesTable(timesTable, upTo, answer);
        theTimesTable.setVisible(true);
        
      } // main
    } // class TimesTable
    here is the code, but i get 3 errors when compiled:

    TimesTable.java:26: cannot find symbol
    symbol : constructor JLabel(int)
    location: class javax.swing.JLabel
    contents.add(new JLabel(i));
    ^
    TimesTable.java:28: cannot find symbol
    symbol : constructor JLabel(int)
    location: class javax.swing.JLabel
    contents.add(new JLabel(timesTable));
    ^
    TimesTable.java:29: cannot find symbol
    symbol : constructor JLabel(int)
    location: class javax.swing.JLabel
    contents.add(new JLabel(answer));

    Any suggestions guys? I'm really stuck.

    It's supposed to output something like this on a GUI.

    for e.g. java TimesTable 3 10

    1 X 3 = 3
    2 X 3 = 6
    .... etc

    Kind regards

    Shyam

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default

    JLabel does not have a constructor that takes an int.
    That's all those errors are telling you.
    It has two single-parameter constructors, one taking an Icon and the other taking a String.

Posting Permissions

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