by Dinesh Thakur

 

import java.awt.*;

import javax.swing.*;
import java.awt.event.*;
public class JavaExampleMenuImagesInJApplet extends JApplet implements ActionListener
  {
      ImageIcon Icn = new ImageIcon("Java.jpg");
      public void init()
       {
           JMenuBar MnuBar = new JMenuBar();
           JMenu MnuOne = new JMenu("File");
           JMenuItem MnuItmOne = new JMenuItem("New...", Icn),
           MnuItmTwo = new JMenuItem("Open...", Icn),
           MnuItmThree = new JMenuItem("Exit", Icn);
           MnuOne.add(MnuItmOne);
           MnuOne.add(MnuItmTwo);
           MnuOne.addSeparator();
           MnuOne.add(MnuItmThree);
           MnuItmOne.setActionCommand("You selected New");
           MnuItmTwo.setActionCommand("You selected Open");
           MnuItmOne.addActionListener(this);
           MnuItmTwo.addActionListener(this);
           JMenu MnuTwo = new JMenu("Edit");
           JMenuItem MnuItmFour = new JMenuItem("Cut", Icn),
           MnuItmFive = new JMenuItem("Copy", Icn),
           MnuItmSix = new JMenuItem("Paste", Icn);
           MnuTwo.add(MnuItmFour);
           MnuTwo.add(MnuItmFive);
           MnuTwo.add(MnuItmSix);
           MnuItmFour.setActionCommand("You selected Cut");
           MnuItmFive.setActionCommand("You selected Copy");
           MnuItmSix.setActionCommand("You selected Paste");
           MnuItmFour.addActionListener(this);
           MnuItmFive.addActionListener(this);
           MnuItmSix.addActionListener(this);
           MnuBar.add(MnuOne);
           MnuBar.add(MnuTwo);
           setJMenuBar(MnuBar);
        }
           public void actionPerformed(ActionEvent e1)
            {
               JMenuItem MnuItm = (JMenuItem)e1.getSource();
               showStatus(MnuItm.getActionCommand());
            }
 }
/*<APPLET  CODE =JavaExampleMenuImagesInJApplet.class WIDTH = 350 HEIGHT = 280 ></APPLET>*/

Java - Add Icon to Menu Item Example