473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Java applet Math.Random wont work

10
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().width),(i nt)(Math.random()*getSize().height),20,20);

any help you can provide will be greatly appreciated
Jan 8 '08 #1
2 2636
BigDaddyLH
1,216 Expert 1GB
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().width),(i nt)(Math.random()*getSize().height),20,20);

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:

Expand|Select|Wrap|Line Numbers
  1. double x = java.lang.Math.random();
But in this case, I invite you to learn about class java.util.Random:

http://java.sun.com/javase/6/docs/ap...il/Random.html

It's easier to use than Math's random method.
Jan 8 '08 #2
Helmer
10
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:

Expand|Select|Wrap|Line Numbers
  1. double x = java.lang.Math.random();
But in this case, I invite you to learn about class java.util.Random:

http://java.sun.com/javase/6/docs/ap...il/Random.html

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.random, sounds good, thanks for your help.
Jan 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
2
by: Christian Galbavy | last post by:
Hy! My next problem is to make an applet from my program. I have just add the "extend applet" to my class and removed the main-method by the start-method of the applet. I was thinking that this...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
by: belog | last post by:
can i post this to my friendster > <script language="JavaScript"> // Under Water Mouse - Kurt Grigg - // http://www.btinternet.com/~kurt.grigg/javascript n4=(document.layers);...
5
by: IndependentDreams | last post by:
This is a java script code that will make it snow on your page. My problem is that it works just fine in IE and Opera, but doesn't work in Fire Fox or Safari. Here is the code. If you have any idea...
4
by: JNeko | last post by:
hello all, I have tried my hand at this for a couple hours but no luck. I am using JCreator. I used these two links for reference: http://www.tech-recipes.com/java_programming_tips1265.html...
7
by: devilinthebox | last post by:
I'm fairly new to java and need help with adding letters (J, Q, K, A) into the program and adding values for each. Thanks. // February 8, 2008 // The "BlackJack" class. import java.awt.*;...
3
by: Robert Larsen | last post by:
Hi all I have a small problem with a signed applet. The applet works fine but some users wont click 'yes' to give the applet further privileges (that is ok too). If the user dont give the applet...
10
by: yeshello54 | last post by:
Hey guys i am pretty new to java swing and need some help. I am developing a simple color chooser program in swing. I have a color panel that is connected to three sliders. red green and blue. but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.