Bonjour,

mon appli consiste à recuperer les valeurs a1,a2 ....que l 'utilsateur a entré dans diff textField, et selon l item de la comboBox avec laquelle est associé le TextField,
Je recalcule a1=a1*4.333 ou a1=a1 respectivement l'utilsateur a selectionne weekly ou monthly dans la comboBox

Voici la definition de ma classe
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
 
     calculatePerPeriod(tf_loans,cb_loans,loans);
     calculatePerPeriod(tf_wages,cb_wages,wages);
     calculatePerPeriod(tf_otherIncome,cb_otherIncome,otherI);
     totalIncome = loans + wages + otherI ;
     System.out.println("total Income "+totalIncome) ;
     calculatePerPeriod(tf_rent,cb_rent,rent);
     calculatePerPeriod(tf_food,cb_food,food);
     calculatePerPeriod(tf_otherSpending,cb_otherSpending,otherS);
      totalSpending = rent + food + otherS ;
Comme j'ai bcp de TextField ,
j 'ai créée une fonction que je veux utiliser a chaque fois
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
 public void calculatePerPeriod(JTextField tf, JComboBox cb, double db){
        if (cb.getSelectedItem().equals("Weekly"))
        { db = (Double.parseDouble(tf.getText())*4.3333) ; }
        else db = (Double.parseDouble(tf.getText())) ;
    }
et voila ce que le bouton calculate fait :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
 
     calculatePerPeriod(tf_loans,cb_loans,loans);
     calculatePerPeriod(tf_wages,cb_wages,wages);
     calculatePerPeriod(tf_otherIncome,cb_otherIncome,otherI);
     totalIncome = loans + wages + otherI ;
     System.out.println("total Income "+totalIncome) ;
     calculatePerPeriod(tf_rent,cb_rent,rent);
     calculatePerPeriod(tf_food,cb_food,food);
     calculatePerPeriod(tf_otherSpending,cb_otherSpending,otherS);
      totalSpending = rent + food + otherS ;
Le truc c 'est que mes double comme loans ou wages reste toujours nuls ?
Comment se fait ce ?


Merci