Java applet Math.Random wont work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Helmer
    New Member
    • May 2007
    • 10

    #1

    Java applet Math.Random wont work

    i am in programming class trying to make an applet involving random placement of colored blocks, but an error is created when i try to run it saying "no method named "random" was found in type "Math". "

    i have imported java.awt like so:
    import java.awt.*;

    and this is the random number statement:
    g.fillRect((int )(Math.random() *getSize().widt h),(int)(Math.r andom()*getSize ().height),20,2 0);

    any help you can provide will be greatly appreciated
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by Helmer
    i am in programming class trying to make an applet involving random placement of colored blocks, but an error is created when i try to run it saying "no method named "random" was found in type "Math". "

    i have imported java.awt like so:
    import java.awt.*;

    and this is the random number statement:
    g.fillRect((int )(Math.random() *getSize().widt h),(int)(Math.r andom()*getSize ().height),20,2 0);

    any help you can provide will be greatly appreciated
    You probably defined a class and gave it the name Math, so there's confusion between the two. One way to disambiguate is to use the fully qualified named:

    [CODE=Java]double x = java.lang.Math. random();[/CODE]

    But in this case, I invite you to learn about class java.util.Rando m:



    It's easier to use than Math's random method.

    Comment

    • Helmer
      New Member
      • May 2007
      • 10

      #3
      Originally posted by BigDaddyLH
      You probably defined a class and gave it the name Math, so there's confusion between the two. One way to disambiguate is to use the fully qualified named:

      [CODE=Java]double x = java.lang.Math. random();[/CODE]

      But in this case, I invite you to learn about class java.util.Rando m:



      It's easier to use than Math's random method.
      well i didnt define any classes with teh name math, but i will look into the java.util.rando m, sounds good, thanks for your help.

      Comment

      Working...