import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JavaExampleMenuDisableInJApplet 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("Disable Bottom Item"),
MnuItmFive = new JMenuItem("Enable Bottom Item"),
MnuItmSix = new JMenuItem("Enabled Item");
public void init()
{
MnuOne.add(MnuItmOne);
MnuOne.add(MnuItmTwo);
MnuOne.addSeparator();
MnuOne.add(MnuItmThree);
MnuItmOne.setActionCommand("You Choose New");
MnuItmTwo.setActionCommand("You Choose Open");
MnuItmOne.addActionListener(this);
MnuItmTwo.addActionListener(this);
MnuTwo.add(MnuItmFour);
MnuTwo.add(MnuItmFive);
MnuTwo.add(MnuItmSix);
MnuItmFour.setActionCommand("You Choose Cut");
MnuItmFive.setActionCommand("You Choose Copy");
MnuItmFour.addActionListener(this);
MnuItmFive.addActionListener(this);
MnuBar.add(MnuOne);
MnuBar.add(MnuTwo);
setJMenuBar(MnuBar);
}
public void actionPerformed(ActionEvent e1)
{
JMenuItem MnuItm = (JMenuItem)e1.getSource();
if(MnuItm == MnuItmFour)
{
MnuItmSix.setText("Disabled Item");
MnuItmSix.setEnabled(false);
}
if(MnuItm == MnuItmFive)
{
MnuItmSix.setText("Enabled Item");
MnuItmSix.setEnabled(true);
}
}
}
/*<APPLET CODE = JavaExampleMenuDisableInJApplet.class WIDTH = 350 HEIGHT = 280 ></APPLET>*/