File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Smiling Face

 
Andrew Hocker
Greenhorn
Posts: 13
  • 0
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • 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
  • 0
  • 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.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • 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
  • 0
  • 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
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic