Would any body tell me that what is the function of setAction command in the following code. I got beet confuse about this command. Also i would like to know since getActionCommand is a method of Button class then How we r calling it with ActionEvent object.
setActionCommand sets the string that is part of the ActionEvent when the button is clicked. You use it to determine which action should take place in your actionPerformed method. The code looks fine, i.e. you're using the two methods correctly. (Of course, you set "Left", while you check for "left", so that wouldn't work.)