Results 1 to 5 of 5
  1. #1
    Kratos321's Avatar
    Kratos321 is offline Member
    Join Date
    May 2011
    Posts
    31
    Rep Power
    0

    Default 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.

    Java 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
    Last edited by Kratos321; 05-11-2012 at 04:47 AM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default 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.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,413
    Rep Power
    25

    Default Re: JAVA Applet resize to load problem?

    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?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default Re: JAVA Applet resize to load problem?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Kratos321's Avatar
    Kratos321 is offline Member
    Join Date
    May 2011
    Posts
    31
    Rep Power
    0

    Default Re: JAVA Applet resize to load problem?

    @KevinWorkman

    Thank you very much.

Similar Threads

  1. Settlers of Catan Java Applet won't load
    By ragalie in forum Java Applets
    Replies: 5
    Last Post: 02-23-2012, 04:00 PM
  2. Java Applet Will Not Load.
    By PaulMoretti in forum Advanced Java
    Replies: 3
    Last Post: 08-16-2011, 05:19 PM
  3. Replies: 1
    Last Post: 08-14-2011, 03:07 AM
  4. Replies: 0
    Last Post: 03-31-2008, 04:35 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •