• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Quiz applet;Want to disply images

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic