Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quiz applet;Want to disply images

 
rahul nathan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rahul nathan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help alot to see your code...

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).]
 
rahul nathan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you still have a reference to the Label you can use the remove( Component ) method of the Panel or Frame that contains the Label...



Of course, instead of changing labels aroung, you could always just use the setText( String ) method of label to change what the label says... it's quite a bit easier...

-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic