mercredi 20 juillet 2016

how to write an if else statement in java?

I have three jComponents : jTextField1, jButton1 and jTextField2. If i write "A" or "B" on jTextField1, then I clicked the jButton1, will show the results on jtextfield2.

this is my code:

    Double p2 = 0.02;
    Double p3 = 0.04;
    int a1=0, b2=1;

        if(jTextField3.equals("A")){
            Double t = ((p2*a1)*100);
            jTextField7.setText(""+t);
        }
        else if(jTextField3.equals("B")){
            Double t = ((p3*b2)*100);
            jTextField7.setText(""+t);
        }

but, that code doesn't work.

can you help me?

Aucun commentaire:

Enregistrer un commentaire