Java: How to know which menu item is clicked??

Sometimes in java, while we do GUI programming to prepare software we add menu bar(For example javax.swing.JMenuItem jMenuItem).In the menu bar we add various menu items according to our necessity.
While adding menu item, we have to indicate which menu item is clicked and which action need to be performed on that click.

 


Here I have given a code snippet to identify which menu item is clicked.                                              

             private javax.swing.JMenuItem jMenuItem = null;

              private javax.swing.JMenuItem jMenuItem1 = null;

                                                jMenuItem.setText(“Approve” );

                                                jMenuItem1.setText(“Reject” );

               if(jMenuItem.getText().trim().equalsIgnoreCase(“Approve” )   )

                                    {

                                                           Do the following action

——-

—-

                                      }
 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: