I have written code to perform click event on JMenuItem but that is not firing when I am debugging. (I know that I am not supposed to ask these questions in this forum but I am new to this forum)
public class ClsMenu extends JMenuItem implements ActionListener {
JTextArea output;
JScrollPane scrollPane;
public ClsMenu(String text)
{
super(text);
addActionListener(this);
}
public JMenuBar createMenu()
{
JMenuBar menuBar;
JMenu menuFood,menuDrinks,menuParty;
JMenuItem foodItem;
menuBar=new JMenuBar();
menuFood=new JMenu("Food");
foodItem=new JMenuItem("Pizza");
menuFood.add(foodItem);
menuBar.add(menuFood);
return menuBar;
}
public void createGUIandShow()
{
JFrame frame = new JFrame("Restuarant");
frame.setJMenuBar(createMenu());
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("item clicked"+e.getActionCommand());
}
}
在这项呼吁中,我设立了一个物体。
public class ClsMenuDisp {
public static void main(String[] args) {
// TODO Auto-generated method stub
ClsMenu menu=new ClsMenu("testitem");
menu.createGUIandShow();
}
}