I am trying an applet I have been adding to through my study book, and it runs, but not right.. It's supposed to take the name I put in and display it back on the applet screen, but after I click the button I get nothing.. Here's the code:
Did I miss something, or is my pc just too slow to return the new output?
when adding/removing components in this manner you need to call validate() (or revalidate() for swing components), and sometimes repaint() - safer to add it for all
After adding components later in the applet lifecycle (like you are doing in the in the action handler), the applet layout needs to be refreshed. This is done with a call to "invalidate();".
I haven't learned the repaint method yet, but just did the invalidate and validate methods.. Thanks, I got it working now, plus I just read about the remove method.. Here's the working code..
Originally posted by Jeremy Parsons: as a side thought, why do I need two method bodies instead of one like most of the programs I have made using Java? Is it just with Applets or what??
I don't understand the question. What two method bodies?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
It's good software practice to carve up your program into classes and methods, with each having a clearly defined task. You'll get to that later in your studies. Code that does initialization has really nothing to do with code for handling an event. Besides, the init code is called once, while the event handler is called multiple times. You wouldn't want the init stuff to happen over and over again.