You have to pass the Content Pane of your JFrame as the first parameter in the method not just the JFrame like you are doing now. So you need to call your message statement like this (notice that frame.getContentPane()
is used, not just frame):
JOptionPane.showMessageDialog(frame.getContentPane(), "You fired "+comp.getNumBallsFired()+" times\n and you "+
(comp.isTargetHit()?"":"did not")+" hit the target!");
Reference: Here.