walkn
Messages postés96Date d'inscriptionsamedi 2 mai 2009StatutMembreDernière intervention23 avril 2011
-
2 juin 2010 à 14:51
walkn
Messages postés96Date d'inscriptionsamedi 2 mai 2009StatutMembreDernière intervention23 avril 2011
-
3 juin 2010 à 12:58
Bonjour, c'est encore moi!!!
Je voudrais selon le choix de ma combobox effectuer divers operations.
J'ai donc deux methodes ou juste le choix 10 et differents a chaque fois:
void carburant(){
int Res = 0;
double Res1=0;
double Res2=0;
double d10 = 7.3;
int carbu = Integer.parseInt(jTextFieldpourcentage.getText());
double carbu1 = Integer.parseInt(jTextFieldCarbuAV.getText());
double carbu2 = Integer.parseInt(jTextFieldCarbuAR.getText());
double d = 5.4;
double d1 = 4.06;
switch (jComboBox.getSelectedIndex()){
case 1: Res = (int) (carbu * d); break;
case 2: Res = (int) (carbu * d); break;
case 3: Res = (int) (carbu * d); break;
case 4: Res = (int) (carbu * d); break;
case 5: Res = (int) (carbu * d); break;
case 6: Res = (int) (carbu * d); break;
case 7: Res = (int) (carbu * d); break;
case 8: Res = (int) (carbu * d); break;
case 9: Res = (int) (carbu * d1); break;
case 10: Res1 = (double) (carbu1 * d10);
Res2 = (double) (carbu2 * d10);
case 11: Res = (int) (carbu * d1); break;
case 12: Res = (int) (carbu * d1); break;
}
jLabelQuantiteL.setText("" + Res);
jLabelQuantiteAR.setText("" + Res1);
jLabelQuantiteAV.setText("" + Res2);
}
Et la seconde methode:
void masseCarburant(){
double Res = 0;
double Res3=0;
double Res4=0;
double d = 0.79;
int nbLitres = Integer.parseInt(jLabelQuantiteL.getText());
double nbLitresAV = Integer.parseInt(jLabelQuantiteAV.getText());
double nbLitresAR = Integer.parseInt(jLabelQuantiteAR.getText());
switch (jComboBox.getSelectedIndex()){
case 1: Res = (int) (nbLitres * d); break;
case 2: Res = (int) (nbLitres * d); break;
case 3: Res = (int) (nbLitres * d); break;
case 4: Res = (int) (nbLitres * d); break;
case 5: Res = (int) (nbLitres * d); break;
case 6: Res = (int) (nbLitres * d); break;
case 7: Res = (int) (nbLitres * d); break;
case 8: Res = (int) (nbLitres * d); break;
case 9: Res = (int) (nbLitres * d); break;
case 10: Res3 = (double) (nbLitresAV * d);
Res4 = (double) (nbLitresAR * d);
case 11: Res = (int) (nbLitres* d); break;
case 12: Res = (int) (nbLitres* d); break;
}
jLabelMasseCarburant.setText("" + Res);
jLabelLitresAV.setText("" + Res3);
jLabelLitresAR.setText("" + Res4);
}
J'appelle ensuite ces deux methodes dans l'action d emon bouton qui permet d'ouvrir une nouvelle fenetre et recuperer les données:
nouvellefenetre.setLabelText25(jLabelQuantiteL.getText());
nouvellefenetre.setLabelText30(jTextFieldpourcentage.getText());
nouvellefenetre.setLabelText31(jLabelMasseCarburant.getText());//recupere la masse carburant
Et j'ai toujuors une erreur lors de mon choix de comboBox soit sur
double carbu1 = Integer.parseInt(jTextFieldCarbuAV.getText());
et la methode carburant()
soit sur :
int carbu = Integer.parseInt(jTextFieldpourcentage.getText());
et la methode carburant()
walkn
Messages postés96Date d'inscriptionsamedi 2 mai 2009StatutMembreDernière intervention23 avril 2011 2 juin 2010 à 15:36
Je me suis tromper pour la declaration en double,effectivement c'est int.
L'erreur est:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at monPackage2.Demarrage.carburant(Demarrage.java:1748)
at monPackage2.Demarrage$16.actionPerformed(Demarrage.java:1453)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
La ligne 1748 correspond a double carbu1 = Integer.parseInt(jTextFieldCarbuAV.getText());
et l'autre ligne correspond à l'appel de ma methode carburant()
walkn
Messages postés96Date d'inscriptionsamedi 2 mai 2009StatutMembreDernière intervention23 avril 2011 2 juin 2010 à 17:17
J'ai modifier mon code de ma methode:
void carburant(){
int Res = 0;
int Res1=0;
int Res2=0;
double d10 = 7.3;
Integer carbu1=0;
Integer carbu2=0;
Integer carbu=0;
if (!"".equals(jTextFieldCarbuAV.getText())) { //permet de voir si le texte est vide,si il n'y a pas cette instruction le texte vide ne peut pas "passer"
carbu = Integer.parseInt(jTextFieldpourcentage.getText());
}
if (!"".equals(jTextFieldCarbuAV.getText())) {//permet de voir si le texte est vide,si il n'y a pas cette instruction le texte vide ne peut pas "passer"
carbu1 = Integer.parseInt(jTextFieldCarbuAV.getText());
}
if (!"".equals(jTextFieldCarbuAV.getText())) {//permet de voir si le texte est vide,si il n'y a pas cette instruction le texte vide ne peut pas "passer"
carbu2 = Integer.parseInt(jTextFieldCarbuAR.getText());
}
double d = 5.4;
double d1 = 4.06;
switch (jComboBox.getSelectedIndex()){
case 1: Res = (int) (carbu * d); break;
case 2: Res = (int) (carbu * d); break;
case 3: Res = (int) (carbu * d); break;
case 4: Res = (int) (carbu * d); break;
case 5: Res = (int) (carbu * d); break;
case 6: Res = (int) (carbu * d); break;
case 7: Res = (int) (carbu * d); break;
case 8: Res = (int) (carbu * d); break;
case 9: Res = (int) (carbu * d1); break;
case 10: Res1 = (int) (carbu1 * d10);
Res2 = (int) (carbu2 * d10);break;
case 11: Res = (int) (carbu * d1); break;
case 12: Res = (int) (carbu * d1); break;
}
jLabelQuantiteL.setText("" + Res);
jLabelQuantiteAR.setText("" + Res1);
jLabelQuantiteAV.setText("" + Res2);
}
Lorsque je remplie mon FieldPOurcentage (c'est a dire dans tous les case sauf le 10), mon appli se lance mais mes calculs me donnent 0.
Si je remplie les fields CarbuAV et carbuAR j'ai l'erreur:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at monPackage2.Demarrage.additionAV(Demarrage.java:1785)
at monPackage2.Demarrage$16.actionPerformed(Demarrage.java:1408)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013130 2 juin 2010 à 17:25
Salut,
Attention, tu ne textes pas les bons textfield :
if (!"".equals(jTextFieldCarbuAV.getText())) { //permet de voir si le texte est vide,si il n'y a pas cette instruction le texte vide ne peut pas "passer"
carbu = Integer.parseInt(jTextFieldpourcentage.getText());
}
if (!"".equals(jTextFieldCarbuAV.getText())) {//permet de voir si le texte est vide,si il n'y a pas cette instruction le texte vide ne peut pas "passer"
carbu1 = Integer.parseInt(jTextFieldCarbuAV.getText()); // là ok
}
if (!"".equals(jTextFieldCarbuAV.getText())) {//permet de voir si le texte est vide,si il n'y a pas cette instruction le texte vide ne peut pas "passer"
carbu2 = Integer.parseInt(jTextFieldCarbuAR.getText());
}
______________________________________
AVANT de poster votre message, veuillez lire, comprendre, et appliquer notre réglement
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "JLabel"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at monPackage2.Demarrage.Moments(Demarrage.java:2213)
at monPackage2.Demarrage$16.actionPerformed(Demarrage.java:1507)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
J'ai bien mis l'instruction pour verifier si la chaine est vide mais maintenat c'est une autre erreur (For inout string "JLabel")
Je ne vois pas pourquoi?