Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Smiling Face

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a homework assignment that I'm have some trouble with. Since it's an assignment, I was wondering if someone could kind of lead me in the right direction but not give me the answers. The two files are below, java and class.
Class

Implementation of the class
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please tell us what kind of trouble? Does it compile? What are the error messages, if not? If it runs, does it not do what you expect? What do you expect, and what happens instead?
 
Andrew Hocker
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol, really sorry about that. I forgot to include my list of problems that are occurring. First of all, a smiley face is supposed to show and does, but when you choose for it to be sad it just draws the angled sides of the mouth and nothing else.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way your erase method works is a bit dangerous - you're drawing the face as white over top of the current face. On top of that, your erase() calls draw() and then you call draw() yourself.
Java is not command line. It sounds weird, but it's possible that the erase's call to draw() might be coming after your own call to draw(). In other words it would draw the sad face and then draw the "erase" happy face on top of it.
The infinite loop is dangerous as well and may be contributing to the problem. Consider learning how to use event listeners as while(true) rarely gives positive results.
 
Andrew Hocker
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's an eventListener and how can I use one in my case?
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you are writing an applet. Being that this is a homework assignment also leads me to assume you have a textbook. Any Java textbook should have a bit on event listeners - that would be a good source for learning.
I really can't give much more advice without knowing how your program is designed, if you're using Swing, etc.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!