Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-26-2008, 06:46 AM
Member
 
Join Date: Jul 2008
Posts: 5
Rep Power: 0
tanmoy.b81 is on a distinguished road
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 :

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

Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-26-2008, 09:08 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,389
Rep Power: 3
hardwired is on a distinguished road
Default
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 paint 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);
    }
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-28-2008, 06:56 AM
Member
 
Join Date: Jul 2008
Posts: 5
Rep Power: 0
tanmoy.b81 is on a distinguished road
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.............




Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JApplet problems Rgfirefly24 New To Java 2 04-24-2008 07:36 PM
Database to JApplet Preethi New To Java 0 03-26-2008 05:18 AM
Another problem in JApplet :S juju Java Applets 2 12-30-2007 07:46 PM
help with converting to JApplet Simmy AWT / Swing 2 08-09-2007 08:45 AM
JApplet and html paty Java Applets 1 08-02-2007 05:41 PM


All times are GMT +2. The time now is 01:30 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org