473,748 Members | 4,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java applet Math.Random wont work

10 New Member
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
Jan 8 '08 #1
2 2655
BigDaddyLH
1,216 Recognized Expert Top Contributor
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:

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.Rando m:

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 New Member
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.Rando m:

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.rando m, 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
9873
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 ********************************** package Celcom.Client;
2
2878
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 is enough, but it does not work, the file does not appear on the server. I have tried to start the applet local and also from the server, but it does not work. Here is the code: *****************************************
1
9649
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
1
2284
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); n6=(document.getElementById&&!document.all); ie=(document.all); o6=(navigator.appName.indexOf("Opera") != -1)?true:false;
5
2295
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 why i can't get it to work that would be great! <!-- this script got from www.javascriptfreecode.com-Coded by: Krishna Eydatoula --> <!-- Web Site: http://www.javakhafan.9f.com--> <!-- javakhafan.9f.com --> <script> // Set the number of...
4
4033
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 http://forum.java.sun.com/thread.jspa?threadID=441336&start=15&tstart=0 Here is my situation: trying to turn a 3000 line main class into an applet, or create an applet that calls it. whatever works. in a nut shell, here is the structure:
7
6032
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.*; import hsa.Console; import java.util.Random; // Only the Random class import java.util.*; // All classes in the java.util package public class BlackJack
3
2374
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 privileges I show a page telling them that the applet wont work unless they grant the applet privileges and give them a link back to the original page so that they can try again if they want to. But if they follow that link, nothing...
10
4650
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 for some reason i cant get it to work..i will post my code and if anyone has any insight to why my changelistener wont work correctly I would really appreciate it. Thanks. import java.awt.*; import java.awt.event.*; import javax.swing.*; import...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.