aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Paint Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Paint Method" Watch "Paint Method" New topic
Author

Paint Method

Tinks1980
Greenhorn

Joined: Sep 25, 2002
Posts: 1
I have created an applet and i am initialising my button in the init. But i am adding the buuton to the panel in the paint method and i am calling the repaint method in the start could u please help because the control is not visible as soon as the applet is loaded as well as when i lose the focus of the applet and get the focus of the applet again. I am also tying the code below for further understanding:
import javax.swing.*;
import java.awt.*;
public class Applettry extends JApplet
{
int count;
JButton b1;
JPanel panel;
public void init()
{
count=0;
panel=new JPanel();
getContentPane().add(panel);
b1=new JButton(String.valueOf(count));
}
public void start()
{
count++;
repaint();
}
public void paint(Graphics g)
{
panel.add(b1);
showStatus("trying");
}
}
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
you should not overwrite paint() without calling super.paint() at some point in the implementation.
And why don't you add the button in the init() method?
chantal
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
tinks1980
Welcome to the JavaRanch! Please adjust your display name to meet
the JavaRanch Naming Policy. You can change it here.
Thanks!
and welcome to the JavaRanch!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Paint Method
 
Similar Threads
problems with repainting the screen
combining controls and graphics
Not able to change Background color of a component
Not to show the ellipse?
adding controls to JFrame