I'd like the program to cancel the whole process when the NO_OPTION is chosen, only showing the output "The price has not been changed". But when I press the No-button the showInputDialog option is started. What am I doing wrong? Thanks in advance.
import javax.swing.JOptionPane;
public class Gebrauchtwagen {
public static void main (String... args){
Auto Auto1 = new Auto(8999.99, "VW Golf", 2007, 56845, "blau");
System.out.println(Auto1.getPreis());
System.out.println(Auto1.getModell());
System.out.println(Auto1.getBaujahr());
System.out.println(Auto1.getKilometerstand());
System.out.println(Auto1.getFarbe());
int dialogButton = JOptionPane.YES_NO_OPTION;
JOptionPane.showConfirmDialog(null, "Wollen Sie den Preis des Fahrzeuges ändern?", "Frage", dialogButton);
if(dialogButton == JOptionPane.YES_OPTION) {
String eingabe = JOptionPane.showInputDialog("Der geänderte Preis:");
double preisNeu = Double.parseDouble(eingabe);
Auto1.setPreis(preisNeu);
System.out.print("Der neue Preis beträgt:"+Auto1.getPreis());
}
if(dialogButton == JOptionPane.NO_OPTION) {
System.out.print("The price has not been changed.");
}
}
}