Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Paint Method

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
}
}
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
permaculture is giving a gift to your future self. After reading this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic