If on Jframe Netbeans

1

I have a doubt I have executed this program in which in netbeans it makes a judgment that if money is less than total it leaves cantidad no suficiente and, if you re-enter it, and this time it is enough, then the invoice will come out .

I know how to run it by java, but I do not know how this same procedure would be done in a JFrame with windows.

For example, if you gave a price in a TextField , this would be money like this raised in the if, and 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:");
    
asked by paola 16.04.2017 в 01:22
source

2 answers

0

you have your jtextfield where the amount will be entered and the button to confirm

private javax.swing.JButton btnConfirmar;
private javax.swing.JTextField txtDinero;

to use the events when clicking the button your Jframe must implement the ActionListener interface so

public class Vista extends javax.swing.JFrame implements ActionListener

then you have to overwrite the actionPerformed method so

 @Override
public void actionPerformed(ActionEvent e) {
    double total = 2000;
    double monto = Double.parseDouble(txtDinero.getText());
    if (monto < total) {
        JOptionPane.showMessageDialog(null, "MONTO INSUFICIENTE");
    } else {
        JOptionPane.showMessageDialog(null, "MONTO SUFICIENTE GENERANDO FACTURA");
    }
}

in your constructor method you add an actionListener to your button so

public Vista() {
    initComponents();
    btnConfirmar.addActionListener(this);

}

I hope you serve as a guide

    
answered by 16.04.2017 / 17:35
source
0

For what I understood you is that you do not have problems with your code but you want to pass it to a graphical interface, no? 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 you need and from there in your code brings the data that the user puts with a jTextfield.getText() that is, instead of scanning you change it by the method that I put you. Then create a button and doubleclick to go to your section within the code, and being there you add your method, the code that you put in this post (obviously complete and with the modifications that I said) and your method you also add JOptionPane.showMessageDialog(this, "tu mensaje"); and this you put in the if sections. For the rest you can see how you want your interface to work and you are modifying things, luck.

    
answered by 16.04.2017 в 16:44