Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Reaction Times Game

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm making a applet, about a users reaction time for when a coloured square changes colour...

Ive seemed to get something off to a bit of a start, but its very basic at the moment, and i would just like to ask for a bit of assistance or guidance as how i can achieve a few things...

Firstsly, check out the code that i've attached so you know what im talking about...When the user clicks to start the game, i want to change the message and colour of square from green to say orange...and maybe have the message change to say 'click when turns red' or something like that...Ive fiddled around with it a lot, but can only get the message to appear AFTER the square has turned red.

Also, you'll see if you try the test, after turning red, it turns green straight away, and then it doesnt change colour until it turns red again.

The reason i want to change this is it is very confusing for users to know if the test has started or not...

Another question i have (sorry, i have lots of issues with the applet) is that i've made a variable to determine if the user has cheated, you will see that it only tells you this after the square has gone red..instead i want it to stop straight away.

Sorry for the long post and many questions!




Thanks for looking at this, and thanks to anyone who has any suggestions about this!

-Crawf
 
Josh Crawford
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, seeing as though no one has had much interest in this post, i wanted to clarify i dont want to ask people how to solve my problem, rather i just want to talk through it with someone with greater knowledge of java than me...

I hope no one has gotten the wrong idea, and thinking im looking for a hand out lol.

But anyway, everyone is probably busy, but i just wanted to make sure!

Thanks!

-Crawf
 
Marshal
Posts: 70727
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did actually have a look at your problem, and got it to work when you first posted it, but was too tired at the time to work out a simple solution. Sorry.

Try:-

In the same places where you change the writing, you can have methods which change the colour of the square. Careful about choice of colours; if you cahnge from orange to red you will get slower reaction times than changing blue to red.
Try something like:-I have no idea whether it will work; I have never tried it.

You can lose two of your methods (I think mouseMoved and mouseEntered), which are not part of the MouseListener interface, and which don't do anything.
 
Josh Crawford
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Sorry about that, i didnt think anyone had taken any notice of my post!

Thanks for having a look at it, where should i put that bit of code by the way? im a little unsure about it...and also, i got rid of mouseMoved, as mouseEntered is still needed...

Thanks!

-Crawf
 
Campbell Ritchie
Marshal
Posts: 70727
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is mouseDragged you can delete.

I have tried various things, and had no success. Sorry.
 
Josh Crawford
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, thanks for having a look at it anyway! i appreciate your efforts!

-Crawf
 
Campbell Ritchie
Marshal
Posts: 70727
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . but while I was in bed, an idea occurred to me.
You can set the foreground colour of an applet at any time.
You can set the colour of a Graphics object to match the foreground . . .

And try playing with the order of the statements of the lines in the mouse clicked method, see whether that improves the display of the writing.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u r using a variable notFirst, but I can't seem to find any declaration for that variable...?
 
Josh Crawford
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah yes, notFirst does nothing, it has no significance, i just forgot to delete that line

-Crawf
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic