JAVA Applet resize to load problem?
Hello everyone,
My problem in the following code is that the modified component only loads when I resize the applet window. When I add the "labelOne" label, it does not appear instantly but only when I resize the output applet. I'm not using the paint() method as I don't need it.
Any help/assistance would be greatly appreciated.
Cheers.
Code:
// The "ListenerTesting" class.
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class ListenerTesting extends Applet implements MouseListener
{
Panel panelOne;
Label labelOne;
public void init ()
{
setLayout (new GridLayout (3, 3));
panelOne= new Panel ();
panelOne.addMouseListener (this);
labelOne= new Label ("X");
add (panelOne);
} //init method
public void mouseClicked (MouseEvent e)
{
if (e.getComponent () == panelOne)
panelOne.add(labelOne);
} //mouseClicked method
public void mouseEntered (MouseEvent e)
{
} //mouseEntered method
public void mouseExited (MouseEvent e)
{
} //mouseExited method
public void mousePressed (MouseEvent e)
{
} //mousePressed method
public void mouseReleased (MouseEvent e)
{
} //mouseReleased method
public void paint (Graphics g)
{
} // paint method
} // ListenerTesting class
Re: JAVA Applet resize to load problem?
After a container is visible, you can't just add components to it and have it magically work. You have to revalidate the component after you add something to it. Check out the API for useful functions.
Re: JAVA Applet resize to load problem?
Quote:
I'm not using the paint() method as I don't need it.
The code overrides the paint method and does nothing. That means the component's paint() method is NOT being called. Is that what you want?
Re: JAVA Applet resize to load problem?
Re: JAVA Applet resize to load problem?
@KevinWorkman
Thank you very much.