if(dialogButton == JOptionPane.YES_OPTION) { // <<< start
System.exit(0);
if(dialogButton == JOptionPane.NO_OPTION) {
remove(dialogButton);
}
}// <<< stop
The result is caused by the fact that the outer if encloses the other if statement, make sure you don't next the if statement, it should be as follows : -
if(dialogButton == JOptionPane.YES_OPTION) {
System.exit(0);
}else {
remove(dialogButton);
}
Another thing is this line int dialogButton = JOptionPane.YES_NO_OPTION;, change it to
int dialogButton = JOptionPane.showConfirmDialog (null, "Are you sure?","WARNING", dialogButton);