I have a doubt. I have executed this program in which in netbeans it makes a statement that if the money is less than the total, it will come out cantidad no suficiente
and, if it is entered again, and this time it is enough, then the invoice will come out.
I know how to execute it by java, but I don't know how this same procedure would be done in a JFrame
windows.
For example, if I said a price in a TextField
, this would be money as stated in the if, and the total would be another TextField
with another amount.
if (dinero< total){
System.out.println("el dinero es INSUFICIENTE.");
System.out.println("\n si desea cambiar la cantidad de dinero digite CORREGIR, sino no lo desea digite CANCELAR");
respuesta= leer.next();
if(respuesta.equalsIgnoreCase("corregir")){
option= true;
}else{
if(respuesta.equalsIgnoreCase("cancelar")){
System.out.println("pedido cancelado.");
option=false;
}else{
System.out.println("el pedido fue cancelado.");
}
}
}
}while(money<total && option!= false);
//--devuelta--//
double devuelta;
if (money>= total){
devuelta= total-money;
System.out.println("Restaurante el Mirador:");
System.out.println("FACTURA:");
From what I understood you is that you don't have problems with your code but you want to pass it to a graphical interface right? If that is the case and you already know the basics of how the interface works, I suggest the following:
Make your interface, place the jTextFileds that you need and from there in your code it brings the data that the user enters with a
jTextfield.getText()
ie, instead of scanning you change it by the method that I gave you. Then create a button and double-click it to go to its section within the code, once there you add your method, the code that you put in this post (obviously complete and with the modifications that I told you) and you also add your methodJOptionPane.showMessageDialog(this, "tu mensaje");
and this you put it in the sections of theif
. For the rest, see how you want your interface to work and modify things, good luck.you have your jtextfield where the amount will be entered and the button to confirm
To use the events when clicking the button, your Jframe must implement the ActionListener interface like this
so you have to override the actionPerformed method like this
in your constructor method you add an actionListener to your button like so
I hope it serves as a guide