Results 1 to 3 of 3

Thread: JApplet Problem

  1. #1
    tanmoy.b81 is offline Member
    Join Date
    Jul 2008
    Posts
    5
    Rep Power
    0

    Default JApplet Problem

    hello everybody,

    I am new to this forum as well as in AWT/Swing. I am facing a problem and do not know how to solve this problem.

    My code :

    Java Code:
    import java.awt.*;
    import javax.swing.*;
     
    public class NewClass extends JApplet{
     
    public void init() {
    JButton jb = new JButton("Send");
    jb.setVisible(true);
    getContentPane().add(jb);
    }
    public void paint(Graphics g) {
    g.drawString("Hello",10,10);
    }
    }
    Now my problem is first time the button is not visible, when I am moving the mouse pointer on that area then the button is being visible.

    Why it is happening like this?

    Please help me out..........

    Thanks in advance...........................
    :o
    :o

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    //  <applet code="NewClassApplet" width="400" height="400"></applet>
    import java.awt.*;
    import javax.swing.*;
     
    public class NewClassApplet extends JApplet {
    
        public void init() {
            JButton jb = new JButton("Send");
            // This is useless here.
            //jb.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(jb);
            getContentPane().add(panel);
            // An alternate approach:
            //getContentPane().add(panel, "Last");        
        }
    
        public void paint(Graphics g) {
            // One of the few times you need to call
            // "super" in a [i]paint[/i] method is if
            // the container has light-weight children.
            // This method will draw on top of children.
            super.paint(g);
            g.drawString("Hello",10,10);
        }
    }

  3. #3
    tanmoy.b81 is offline Member
    Join Date
    Jul 2008
    Posts
    5
    Rep Power
    0

    Thumbs up Thanks lot hardwired

    hi hardwired,
    Thanks a lot for replying me. It's working properly. I have posted this thread on various forums but nobody replied me. Thanks to u and this forum for solving my problem. It's really helpful for me.

    Thanks again.............
    :D
    :D
    :D
    :D
    :D

Similar Threads

  1. JApplet problems
    By Rgfirefly24 in forum New To Java
    Replies: 2
    Last Post: 04-24-2008, 08:36 PM
  2. Database to JApplet
    By Preethi in forum New To Java
    Replies: 0
    Last Post: 03-26-2008, 06:18 AM
  3. Another problem in JApplet :S
    By juju in forum Java Applets
    Replies: 2
    Last Post: 12-30-2007, 08:46 PM
  4. help with converting to JApplet
    By Simmy in forum AWT / Swing
    Replies: 2
    Last Post: 08-09-2007, 09:45 AM
  5. JApplet and html
    By paty in forum Java Applets
    Replies: 1
    Last Post: 08-02-2007, 06:41 PM

Posting Permissions

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