public class ExitCallBack implements ActionListener { public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog(null, "Are you sure?"); if(result == 0){ System.exit(0); } }
} public TicTacToe() { setTitle("Tic Tac Toe"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
grid = new JPanel(); b1 = new JButton(""); b2 = new JButton(""); b3 = new JButton(""); b4 = new JButton(""); b5 = new JButton(""); b6 = new JButton(""); b7 = new JButton(""); b8 = new JButton(""); b9 = new JButton("");
JMenuBar bar = new JMenuBar();//make a bar JMenu file = new JMenu("File");//make a menu to click on (file, about, help, edit, etc.) JMenuItem exit = new JMenuItem("Exit");//make an item that will go into a menu(save, save as, import, export, etc.)
file.add(exit);//add the exit button to the file menu bar.add(file);//add the file menu to the bar
add(bar, BorderLayout.NORTH);//add bar to the window exit.addActionListener(new ExitCallBack());//connect the callback with the exit menu