Q:

Issues with ActionListener(Java)

Possible Duplicate:
Issues with ActionListener (Java) 

I am trying to implement action listener on two buttons in JFrame, but the issue is one of the two button is performing both the functions; but i've not configured it to do so. 
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class MyChangingCirlce implements ActionListener {
    JButton colorButton, labelButton;
    JLabel myLabel;
    MyDrawPanel mdp;
    JFrame frame;

    public static void main(String[] args) {
        MyChangingCirlce mcc = new MyChangingCirlce();
        mcc.createFrame();
    } // end of main

    public void createFrame() {
        frame = new JFrame();
         colorButton = new JButton("Changing Colors");
         labelButton = new JButton("Change Label");
        myLabel = new JLabel("I'm a label");
        mdp = new MyDrawPanel();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.getContentPane().add(BorderLayout.CENTER, mdp);
        frame.getContentPane().add(BorderLayout.SOUTH, colorButton);
        frame.getContentPane().add(BorderLayout.EAST, labelButton);
        frame.getContentPane().add(BorderLayout.WEST, myLabel);
        colorButton.addActionListener(this);
        labelButton.addActionListener(this);
        frame.setSize(300, 300);
        frame.setVisible(true);

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == colorButton) {
            frame.repaint();
        } else {
            myLabel.setText("That's it");
        }

    }

}

My labelButton is performing both the action only 1 time; i.e it changes the color of the circle along with the label text.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MyDrawPanel extends JPanel{

    public void paintComponent(Graphics g)
    {
        int red = (int) (Math.random() * 255);
        int green = (int) (Math.random() * 255);
        int blue= (int) (Math.random() * 255);
        Color randomColor = new Color(red,green,blue);
        g.setColor(randomColor);
        g.fillOval(20,70,100,100);
    }
}

A:

You override colorButton and labelButton. So the 'else' is always kicking in. Changing the label will cause a redraw.
change
    JButton colorButton = new JButton("Changing Colors");
    JButton labelButton = new JButton("Change Label");

to
    colorButton = new JButton("Changing Colors");
    labelButton = new JButton("Change Label");

After writing myself a class to test it, I came about with this:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Date;

public class Foo implements ActionListener {

    JButton colorButton, labelButton;
    JLabel myLabel;
    JFrame frame;
    MyDrawPanel mdp;

    public static void main(String[] args) {
        Foo mcc = new Foo();
        mcc.createFrame();
    } //end of main

    public void createFrame() {
        frame = new JFrame();
        colorButton = new JButton("Changing Colors");
        labelButton = new JButton("Change Label");
        myLabel = new JLabel("I'm a label");
        mdp = new MyDrawPanel();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        mdp.setPreferredSize(new Dimension(150, 150));
        jsp.setLeftComponent(mdp);
        frame.setBounds(10, 10, 600, 600);
        JPanel right = new JPanel();
        right.add(BorderLayout.SOUTH, colorButton);
        right.add(BorderLayout.EAST, labelButton);
        right.add(BorderLayout.WEST, myLabel);
        jsp.setRightComponent(right);
        frame.getContentPane().add(jsp);
        colorButton.addActionListener(this);
        labelButton.addActionListener(this);
        frame.setVisible(true);

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == colorButton) {
            myLabel.setText("Color button's it");
            frame.repaint();
        } else {
            myLabel.setText("That's it" + new Date().toString());
        }

    }

    public class MyDrawPanel extends JPanel {

        @Override
        public void paintComponent(Graphics g) {
            int red = (int) (Math.random() * 255);
            int green = (int) (Math.random() * 255);
            int blue = (int) (Math.random() * 255);
            Color randomColor = new Color(red, green, blue);
            g.setColor(randomColor);
            g.fillOval(20, 70, 100, 100);
        }
    }
}

