Hi All, I've a quiz applet.My applet displays a question using Label,shows answers using Choice and a Button to submit the answers. Now when the user selects the answer and presses the button,i want to display either a tick mark or a cross mark(gif images),based on whether the question is answered correctly/wrongly. Can anyone in this forum help me out,i'm really struck. thanks.
Hi Rahual, What are you stuck on? The easiest would be to have three images: tick, cross, empty/question mark. Just place the one you want into a panel or canvas. Use the button ActionListener to swap the images. NOTE: The empty/question mark image is only needed because panel/canvas have a perferred size that might be queried by the layout manager. Regards, Manfred.
posted 18 years ago
Manfred. Thanks for your reply.Would you mind giving me a piece of code. I wrote a simple applet,this time i didnt use images i used Label's(displaying Right and Wrong )instead.Now when i select my answer and click the button,i could see the label only when i resize my applet,is there anything i'm missing? Also,If i press the submit button again,i'm getting one more Label..rather than replacing the old Label. Expecting your reply, Rahul.
Sounds like you are dynamically adding components without re-validating the screen... try adding validate() right after you change Labels... if you are ending up with two Labels, that means that you didn't remove the old one before adding the new one...
To do the changing images, I would make a subclass of Canvas or Panel that you could send Images to, and then tell it which one to display... something kinda like this...
And here's a tester class to show how to use it...
-Nate [This message has been edited by Nathan Pruett (edited August 22, 2001).]
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
posted 18 years ago
"Sounds like you are dynamically adding components without re-validating the screen... try adding validate() right after you change Labels... if you are ending up with two Labels, that means that you didn't remove the old one before adding the new one..." This really helped thank you very much for your time.Now how do i remove my old Label?I need to use update method? thanks.