Java Help

Discussion in 'Mac Programming' started by Halamire, Apr 28, 2013.

  1. Halamire, Apr 28, 2013
    Last edited: Apr 29, 2013

    macrumors regular

    Halamire

    Joined:
    Dec 31, 2009
    #1
    Any of you good at java? I have a quick question
    My code wont compile. The error is in the main method. Every time i try to call hr and m to get the randomly generated time to compare with the user time, it gives me the red error line.
    Am i not linking the class to the Main method right?
     
  2. macrumors member

    Joined:
    Dec 6, 2010
    #2
  3. macrumors regular

    Joined:
    May 16, 2005
    Location:
    Ontario, Canada
    #3
    I think you accidentally forgot to create the variable "s". You could change
    Code:
    private static final SwingCanvas SwingCanvas = null;
    to
    Code:
    private static SwingCanvas s = null;
    and then change your Clock constructor to set that variable by changing
    Code:
    setContentPane(new SwingCanvas());
    to
    Code:
    s = new SwingCanvas();
    setContentPane(s);
    It has been years since I've done Java GUI development so I have no idea if you are following best practices but these changes will at least fix your error.

    Hope this helps,

    Andrew
     
  4. thread starter macrumors regular

    Halamire

    Joined:
    Dec 31, 2009
    #4
    Thank you so much! Other than my if statements it works!
     

Share This Page