public void actionPerformed(ActionEvent event) {
        this.setVisible(false);     //hide current frame
        prevScreen.setVisible(true); //open the prev frame
        JMenuItem menu = (JMenuItem) event.getSource(); //error at here
        if (menu == menuItemAdd) {
            addNewRow();
        } else if (menu == menuItemRemove) {
            removeCurrentRow();
        } else if (menu == menuItemRemoveAll) {
            removeAllRows();
        }
    }
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JButton cannot be cast to javax.swing.JMenuItem
    at Addnewbook.actionPerformed(Addnewbook.java:109)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
After I insert the button, I cannot add my data into the table; it suddenly close my JTable frame and back to homepage. I've already search through all forum and other web but still cant find the answer. So is there any way to make the button works with the table? Thanks!
 
     
    