Hi,
I am wondering why , when I click on the "Add Student" button on the GUI,the message dialog is not popping up. I might be doing something wrong but can't figure it out.
Thanks
import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class MainWindow extends JFrame implements ActionListener { JButton addStudent = new JButton("Add Student"); JButton delStudent = new JButton("Delete Student"); JButton updateStudent = new JButton("Update Student"); JButton searchStudent = new JButton("Search Student"); JButton displayStudent = new JButton("Display Students"); JButton addCourse = new JButton("Add Course"); JButton delCourse = new JButton("Delete Course"); JButton updateCourse = new JButton("Update Course"); JButton searchCourse = new JButton("Search Course"); JButton displayCourse = new JButton("Display Courses"); private class WindowDestroyer extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } public MainWindow(){ super("Main Window"); setSize(300,300); setLayout(new GridLayout(5,2)); add(addStudent); add(addCourse); add(delStudent); add(delCourse); add(updateStudent); add(updateCourse); add(searchStudent); add(searchCourse); add(displayStudent); add(displayCourse); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { String action = e.getActionCommand().trim().toString(); switch(action){ case "Add Student" : JOptionPane.showMessageDialog(addStudent, "add button pressed!"); break; case "Add Course" : JOptionPane.showMessageDialog(addCourse, "add button pressed"); break; case "Delete Student": JOptionPane.showMessageDialog(delStudent, "delete button pressed"); break; }; } public static void main(String[] args) { MainWindow f = new MainWindow(); } }