Please explain why nothing happens when I press button 2, but I get the expected result when I press button 1 in the following Java code
<p>My code works only if i press the "button 1" but when i press "button 2" nothing happens.
I know something wrong with my <code>paint()</code> method and the <code>if...else</code> statement, but have no idea how to fix it.</p>

<p>thank you </p>

<pre><code>import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class AnAppletWithButtons extends Applet implements ActionListener
{
    Button button1, button2;
    int r, g , b;
    Color color;
    boolean drawLine = false;
    boolean fillOval = false;

    public void init()
    {
        String parmStringRED =  getParameter("red");
        r = Integer.parseInt(parmStringRED);
        String parmStringGREEN =  getParameter("green");
        g = Integer.parseInt(parmStringGREEN);
        String parmStringBLUE =  getParameter("blue");
        b = Integer.parseInt(parmStringBLUE);
        color = new Color (r,g,b);
        button1 = new Button("Button 1");
        add(button1);
        button1.addActionListener(this);

        button2 = new Button("Button 2");
        add(button2);
        button2.addActionListener(this);
        button1.setForeground(color);
        button2.setForeground(color);

        button1.setBackground(Color.yellow);
        button2.setBackground(Color.yellow);
    }

    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == button1) {
            System.out.println("Button 1 was pressed");
            drawLine = true;
        } else if (e.getSource() == button2) {
            System.out.println("Button 2 was pressed");
            fillOval = true;
        }
        repaint();
    }
    public void paint(Graphics g)
    {
        super.paint(g);   // for the background
        if(drawLine){
            System.out.println(drawLine);
            g.drawLine(0, 0, 400, 400);
        }
        else if(fillOval){
            System.out.println(fillOval);
            g.fillOval(10, 10, 390, 390);
        }

    }
}
</code></pre>
