Computer Science Canada Screen won't update. |
Author: | Reality Check [ Thu Mar 08, 2007 8:33 pm ] | ||
Post subject: | Screen won't update. | ||
I'm fairly new to Java and I'm making a guessing game for an assignment. Here is my code:
Now, the user clicks a box and I tell them if the number is higher or lower. I've only implemented the "lower" part but the screen only outputs lower if I minimize and restore again. Can someone help me fix this? |
Author: | ericfourfour [ Fri Mar 09, 2007 12:52 am ] | ||||||||
Post subject: | Re: Screen won't update. | ||||||||
The curly brackets, in Java, should not have a newline in front of them and should be next to the statement or declaration. ex.
should be
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html is a very useful page on Java code conventions.
tisk, tisk, tisk... Instance variable should be assigned a value in constructors. Trust me, it will make your program a lot easier to work with.
Are you sure this line is required? I thought java.lang.* was automatically imported. Anyway, about the error. I haven't run your program but I can state a few solutions. Is the paint method being called when you want it to? Are you sure you aren't mixing up the colours? Are you sure you are drawing in the correct order (ie. foreground goes above background)? It does not look like you are using a double buffer, but if you are, are you sure you are drawing the buffered image at the correct time? |
Author: | Reality Check [ Fri Mar 09, 2007 10:44 am ] |
Post subject: | Re: Screen won't update. |
Thanks a lot for the suggestions. Like I said, I've only been doing Java for a couple of weeks. In terms of the curly brackets, my teacher insists that they be put under and not next to it because she says its easier to read but I did know that the convention was to put them next to it. I did get it to fix though. Every time the mouse is clicked (in the mouseDown event) I simply put in "repaint ();" at the end of it right before my return statement. |