KeyPressed event in java

Depending on where you want to trap the “enter” key, you could use an ActionListener (on such components such as text components or buttons) or attach a key binding to you component This will rely on the component being focused.

repaint() Method in Java

The repaint() refreshes the view (component), so whenever you make any change on the component, you must call it. For instance, if you rotate the graphical component, you must make a call to repaint() in order to see the change on the containing component

JOptionPane YES NO OPTION

You should actually take the result from the option pane: Otherwise, it remains set to JOptionPane.YES_NO_OPTION. Cleaner would be: Although, I’m not sure what this line is expected to do in the posted code: remove(dialogButton);. For more details and examples check out How to Make Dialogs tutorial.