I'm having a problem getting the Exit option in my Menu to execute the System.exit(0); line in my code.
Any help would be greatly appreciated.
I'm pretty new to forums, and I can't figure out how to attach my code, so I'll just paste it here. The "Manage Attachments" button didn't do anything.
Also, I had to replace the AT symbol (shift 2) with "at" in order to post my question.
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class MenuTest { private static void createAndShow() { JFrame frame = new JFrame("FrameDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel emptyLabel = new JLabel(""); emptyLabel.setPreferredSize(new Dimension(500, 500)); frame.getContentPane().add(emptyLabel, BorderLayout.CENTER); JMenuBar menuBar = new JMenuBar(); JMenu menuExit = new JMenu("Exit"); menuBar.add(menuExit); frame.setJMenuBar(menuBar); menuExit.addActionListener(new ActionListener() { "at"Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd == "Exit") System.exit(0); } }); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShow(); } }); } }