Я создал JOptionPane
и он имеет только две кнопки YES_NO_OPTION
.
После того, как JOptionPane.showConfirmDialog
выскочит, я хочу нажать YES BUTTON
, чтобы продолжить открытие JFileChooser
, и если я нажал NO BUTTON
, он должен отменить операцию.
Это выглядит довольно легко, но я не уверен, где моя ошибка.
Фрагмент кода:
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){
}
}