by Dinesh Thakur

 

import java.awt.*;

import javax.swing.*;
import java.awt.event.*;
public class JavaExampleMenuUpdateInJApplet extends JApplet implements ActionListener
     {
         JMenuBar MnuBar = new JMenuBar();
         JMenu MnuOne = new JMenu("File");
         JMenu MnuTwo = new JMenu("Edit");
         JMenuItem MnuItmOne = new JMenuItem("New..."),
         MnuItmTwo = new JMenuItem("Open..."),
         MnuItmThree = new JMenuItem("Exit"),
         MnuItmFour = new JMenuItem("Add item"),
         MnuItmFive = new JMenuItem("Remove item"),
         MnuItmSix = new JMenuItem("New item");
         public void init()
           {
              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);
              MnuTwo.add(MnuItmFour);
              MnuTwo.add(MnuItmFive);
              MnuItmFour.setActionCommand("You selected Cut");
              MnuItmFive.setActionCommand("You selected Copy");
              MnuItmFour.addActionListener(this);
              MnuItmFive.addActionListener(this);
              MnuBar.add(MnuOne);
              MnuBar.add(MnuTwo);
              setJMenuBar(MnuBar);
           }
              public void actionPerformed(ActionEvent e1)
              {
                 JMenuItem MnuItem = (JMenuItem)e1.getSource();
                 if(MnuItem == MnuItmFour)
               {
                      MnuTwo.add(MnuItmSix);
                   }
                      if(MnuItem == MnuItmFive)
                    {
                           MnuTwo.remove(MnuItmSix);
                        }
              }
  }
/*<APPLET CODE =JavaExampleMenuUpdateInJApplet.class WIDTH = 350  HEIGHT = 280 ></APPLET>*/
JMenuItem Example in Java