This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Cautionary tale about buttons & simple animation  RSS feed

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is for anyone who hasn't yet got to Chapter 12 in the Head First Java book and is as clueless as I seem to be ... or for any old-timers who would like a chuckle ...

The problem is to construct a simple animation: a circle that moves from the top left of the window to the bottom right; the challenge is to write down one's own ideas before looking at the "answer" code.

So, since we had already learned how to hook an event handler to a button, I thought that I would start my animation by clicking a button, since just having an animation start when the window opened seemed a little "retarded". So I wrote my code and figured I would get it to work before turning the page.

Unfortunately, what I got was a circle that started in the upper left corner and reappeared in the lower right corner. And yes, having learned about the Thread.sleep method from the answer to a previous cry for help, I had included a "slow-down" in my code.

So - after much too long of this I finally turned the page. Still couldn't find anything wrong with my code (yes, I knew it wouldn't be exactly the same as what was given). Ultimately, I found out from a friend that I needed to know how to manage thread handling before I could do what I wanted to do ...

Don't know if there's really a "moral" to this story, but thought I would post it in case anyone else gets caught in the same trap.
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, it's cool that you're enhancing the assignments to try things on your own. I guess you wound up with the SwingUtil invoke later stuff? I had some really odd Swing problems myself before I found that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!