Hey guys, I have an assignment due for Thursday for my programming course, its sort of basic Java sort of stuff, but I am pretty stuck on it.
Here is what we are told to do:
[quote]
[B]Reaction Testor[/B]
Write a program that will test a user's mouse control. The program should draw a small circle at a random position. The user should attempt to click the mouse inside the circle as quickly as possible. If the user does manage to click the circle, the circle will disappear and the program will print the time required to click the mouse. After displaying the time, the program draws another circle and the process repeats.
If this seems difficult, just do part of the program.
Remember, to generate a Random integer between 0 and N-1, use Math.random() * N. You will have to cast it to an int, so to assign this number to an int. E.g to generate a random number between 0 and 999, you would use
int x = (int) (Math.random() * 1000);
There are some problems in the lab that contain hints which can help with this problem.
[B]Extra Credit 10%[/B]
Remember the fastest time and print a message if the user beats the previous record.[/quote]
Basically I am stuck on the whole click on the button method, I get errors when I put the circle name in the isPressed method, but when I put the window name in it works, but It has to work on the circle.
Any help would be great, here is the code I have so far:
[quote]import graphics.*;
public class reaction
{
public static void main(String [] args)
{
int window_x = (int) (Math.random() * 900 + 1);
int window_y = (int) (Math.random() * 900 + 1);
long start = 0;
long stop = 0;
Window win = new Window(500, 500);
Color red = new Color (255, 0, 0);
win.setForeground(red);
Circle click = new Circle(window_x, window_y, 30);
win.draw(click);
win.fill(click);
System.out.println ("" + window_x + "");
System.out.println ("" + window_y + "");
while(!win isPressed):
;
if(win.isPressed());
win.erase(click);
}
}
[/quote]
FT is full of 12 year old children nowadays, so you have a better chance of getting the answer if you ask in the programming section
[url]http://www.facepunch.com/forums/240-Programming[/url]
Did you code the circle object yourself or are you just using the circle out of the java graphics library? Because I'm pretty sure the graphics object does not have a isPressed method.
I haven't used java in nearly 2 years though so I may be mistaken.
FT? 12?
What? I'm 19 in my 1st year of college.
[editline]8th November 2010[/editline]
[QUOTE=sirbinks;25941199]Did you code the circle object yourself or are you just using the circle out of the java graphics library? Because I'm pretty sure the graphics object does not have a isPressed method.
I haven't used java in nearly 2 years though so I may be mistaken.[/QUOTE]
Well we were told to download some graphics.jar, and then use the export classpath thing, and at the top of my code is the import.*graphics thing, so I think it may be?
I just don't really know where to go from here.
[QUOTE=Over-Run;25941279]
Well we were told to download some graphics.jar, and then use the export classpath thing, and at the top of my code is the import.*graphics thing, so I think it may be?
I just don't really know where to go from here.[/QUOTE]
Well the best advice I can give in that case is to read through the code you downloaded and figure out exactly how the circle object works.(or post it so someone else can tell you how it works.)
that or just create a new class using the circle object and make your own isPressed method
Yeah I did, still really don't understand how I am meant to make the circle disappear with a click when I can't use the click method.
[QUOTE=Over-Run;25941279]FT? 12?
[/QUOTE]
FT = Fast Threads
Sorry, you need to Log In to post a reply to this thread.