JOptionPane YES/No Options Confirm Dialog Box Issue

Я создал JOptionPane и у него только две кнопки YES_NO_OPTION .

После того как JOptionPane.showConfirmDialog выскочит, я хочу нажать YES BUTTON, чтобы продолжить открытие JFileChooser, а если я нажму NO BUTTON, это должно отменить операцию.

Это кажется довольно простым, но я не уверен, где моя ошибка.

Code Snippet:

if (textArea.getLineCount() >= 1) {  //The condition to show the dialog if there is text inside the textArea

    int dialogButton = JOptionPane.YES_NO_OPTION;
    JOptionPane.showConfirmDialog (null, "Would You Like to Save your Previous Note First?","Warning",dialogButton);

    if (dialogButton == JOptionPane.YES_OPTION) { //The ISSUE is here

    JFileChooser saveFile = new JFileChooser();
    int saveOption = saveFile.showSaveDialog(frame);
    if(saveOption == JFileChooser.APPROVE_OPTION) {

    try {
        BufferedWriter fileWriter = new BufferedWriter(new FileWriter(saveFile.getSelectedFile().getPath()));
        fileWriter.write(textArea.getText());
        fileWriter.close();
    } catch(Exception ex) {

    }
}
59
задан StaceyGirl 15 February 2018 в 00:47
поделиться