title: adding components in applet
body: <p>I am making an applet and as part of my applet, I want this to happen: When the user presses "OK", the old components (some radio buttons) are removed, and a new JPanel is added, with a bunch of textfields.</p>
  
  <p>However, I cannot figure out how to add a new component to the applet after it has started. I made the problem simpler by ignoring the removal part (Which I know how to do) and just adding a simple JLabel instead, but even that won't add!</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>// imports omitted
  
  public class Class extends Applet implements ActionListener 
  {
    Button okButton;  
    CheckboxGroup radioGroup; 
    Checkbox radio1; 
    Checkbox radio2; 
    Checkbox radio3;
    JLabel j;
  
    public void init()  
    { 
      setLayout(new FlowLayout()); 
      okButton = new Button("OK"); 
      j = new JLabel("hello");
      radioGroup = new CheckboxGroup(); 
      radio1 = new Checkbox("Red", radioGroup,false); 
      radio2 = new Checkbox("Blue", radioGroup,true); 
      radio3 = new Checkbox("Green", radioGroup,false); 
      add(okButton); 
      add(radio1); 
      add(radio2); 
      add(radio3);
      okButton.addActionListener(this); 
    }
  
    public void repaint(Graphics g) 
    { 
      if (radio1.getState()) add(j); 
    }
  
    public void actionPerformed(ActionEvent evt)  
    { 
      if (evt.getSource() == okButton) repaint();
    } 
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>