Hello. I'm new to Java and, I'm trying to set up a frame with an Exit Button that uses an event handler. But, it isn't working - here is the code, am I missing something? It isn't even getting inside the if statement. Any help would be appreciated
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.GridLayout;
import java.util.EventObject;
JButton bExitButton = new JButton("Exit");
panel.add(bExitButton);
bExitButton.addActionListener(this);
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == bExitButton) {
JOptionPane.showConfirmDialog(null, "Are you sure you want to Exit?", "Alert", JOptionPane.YES_NO_OPTION);
System.exit(0); }
}