Search code examples
javaactionlistenerjoptionpanefileoutputstream

How can I put an actionlistener to the OK button of JOptionpane.showInputDialog?


I have a showInputDialog. Whenever I type something to that field, I want it to be save as textfile when I click the ok button. My problem is I don't know where/how to put the listener.

Could somebody help me about this matter?


Solution

  • The saving code shouldn't be in the InputDialog context, but in your code. InputDialog is just a way to prompt for data.

    String whatHeTyped = JOptionPane.showInputDialog("Type something...");
    saveToFile(whatHeTyped);