This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Repaint  and ComponentListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Repaint  and ComponentListener " Watch "Repaint  and ComponentListener " New topic
Author

Repaint and ComponentListener

Jennifer Wallace
Ranch Hand

Joined: Nov 30, 2001
Posts: 102
Please look into this problem. I have tried to state the problem in simple terms.
Class A extends Canvas.
Class B extends applet and has Cardlayout
The first card is a panel,has borderlayout.
- This contains an instance of "A" in the "CENTER"
- Also, has a panel with a textfield in "SOUTH"
When I leave the browser window containing the applet, and return.
the Canvas in the center is repainted and refreshes itself. But the lower panel is not reset. (The textfield still retains the previous state).
To reset the textfield, I tried to implement class B as a ComponentListener and tried reseting the textfield values in
componentShown(ComponentEvent ce) method of the inteface. Doesnt seem to work on the textfield ?
Is this the right approach ? if so, why would this be not working ?
[ June 26, 2002: Message edited by: Jennifer Wallace ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Are you revalidateing?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jennifer Wallace
Ranch Hand

Joined: Nov 30, 2001
Posts: 102
Thanks ! validate() resets my textfield beautifully. Sorry for the delayed response. Just saw your reply today.
But looks like I have worked up with the wrong listener. Because apparently, the componentshown method of Component Listener is invoked only once initially (atleast in my code) and is not invoked when the applet is repainted on re gaining focus. This contradicts what I saw in the demo applet of java tutorial. Would this not work on applets ?
Also, I tried a couple of others. They didn't work as well - Focus Listener, WindowFocuslistener, WindowListener (the last 2 work only for windows!)
Which listener should I be using, to capture the moment of my return to the applet screen ?
Thanks,
Jennifer
Gowrinath
Greenhorn

Joined: Jul 02, 2002
Posts: 1
Originally posted by Jennifer Wallace:
Thanks ! validate() resets my textfield beautifully. Sorry for the delayed response. Just saw your reply today.
But looks like I have worked up with the wrong listener. Because apparently, the componentshown method of Component Listener is invoked only once initially (atleast in my code) and is not invoked when the applet is repainted on re gaining focus. This contradicts what I saw in the demo applet of java tutorial. Would this not work on applets ?
Also, I tried a couple of others. They didn't work as well - Focus Listener, WindowFocuslistener, WindowListener (the last 2 work only for windows!)
Which listener should I be using, to capture the moment of my return to the applet screen ?
Thanks,
Jennifer

I think MouseMotionListener and MouseListener will allow you to know your presence in the applet
Jennifer Wallace
Ranch Hand

Joined: Nov 30, 2001
Posts: 102
I think Mouse Listeners will not work for me because I want the applets components to be validated when the web page containing the applet gains focus and not wait until the mouse enters the applet.
Also, looks like componentShown method of ComponentListener (Definiton of which is - Invoked when the component has been made invisible) doesn't correspond to the applet window going out of view and getting back focus. I think the demo applet in Sun's Website also demonstrates similar activity.
In fact, the solution would be to validate my components in the applet's paint method. And this works fine and resets my textfield everytime the applet is repainted.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Repaint and ComponentListener
 
Similar Threads
Help with paint to panel
Why does the FlowLayoutManager layout more space than needed?
why do this canvas is covering the entire area of the applet?
some help reqd in painting of Canvas?
applets