Which button has clicked. Java,Netbeans

I make an app in java with Netbeans. At a Jframe Form,I use four buttons. I need to know which of them has clicked by user. Everyone who can help me? Thanks

public class Color extends javax.swing.JFrame implements ActionListener {


public Color() {
        initComponents();


        /////////////////////////////////

        //Register a listener for the  buttons.
        up_button.addActionListener(this);
        down_button.addActionListener(this);
        left_button.addActionListener(this);
        right_button.addActionListener(this);
       }


private int k=1;
    public void actionPerformed(ActionEvent e) {

       k=k+1;


       if (k==1)
       {
         image.setIcon(createImageIcon("color1"
                                        + e.getActionCommand()
                                        + ".PNG"));
       }
       else ...  }

       private void up_buttonActionPerformed(java.awt.event.ActionEvent evt)     {                                          
        // TODO add your handling code here:

    }  

    private void down_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:

    }

    public static void main(String args[]) {

        /* Create and display the form */

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Color().setVisible(true);
            }
        });
    }
Jon Skeet
people
quotationmark

You can call getSource on the ActionEvent to find out the source of the event. That will be one of the buttons.

people

See more on this question at Stackoverflow