IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

[JavaFX] Erreur sur calculatrice


Sujet :

Java

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Septembre 2024
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Septembre 2024
    Messages : 2
    Par défaut [JavaFX] Erreur sur calculatrice
    Bonjour les amis j'espère que vous allez bien. Je viens de me mettre sur javafx et mon premier projet est une calculatrice. J'ai codé toutes les lignes et j'ai connecté avec scène builder mais quand j'appuie sur le bouton "=" ca n'affiche aucun résultat sur la textfild écranResultat. Je précise que c'est le seul problème de mon projet. Je vais joindre des images et le code du projet. Merci de m'aider.
    Voici le code:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    package application;
     
    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
     
    import javafx.scene.control.Button;
     
    import javafx.scene.control.TextField;
     
    public class DesigneController {
    	@FXML
    	private Button btn1;
    	@FXML
    	private Button div;
    	@FXML
    	private Button neg;
    	@FXML
    	private Button vir;
    	@FXML
    	private Button btn0;
    	@FXML
    	private Button mult;
    	@FXML
    	private Button btn9;
    	@FXML
    	private Button btn8;
    	@FXML
    	private Button moins;
    	@FXML
    	private Button btn6;
    	@FXML
    	private Button plus;
    	@FXML
    	private Button btn5;
    	@FXML
    	private Button btn7;
    	@FXML
    	private Button btn4;
    	@FXML
    	private Button btn3;
    	@FXML
    	private Button btn2;
    	@FXML
    	private Button efface;
    	@FXML
    	private Button clean;
    	@FXML
    	private Button egal;
    	@FXML
    	private TextField ecranOperation;
    	@FXML
    	private TextField ecranResultat;
    	@FXML
    	private Double nombre1,nombre2,resultat;
    	@FXML
    	private String operateur;
     
     
     
    	@FXML
    	public void un(ActionEvent event ) {
    		String txt = ecranOperation.getText()+btn1.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void deux(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn2.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void trois(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn3.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void quatre(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn4.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void cinq(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn5.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void six(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn6.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void sept(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn7.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void huit(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn8.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void neuf(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn9.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void zero(ActionEvent event) {
    		String txt = ecranOperation.getText()+btn0.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void virgule(ActionEvent event) {
    		String txt = ecranOperation.getText()+vir.getText();
    		ecranOperation.setText(txt);
    	}
    	@FXML
    	public void add(ActionEvent event) {
    		String txt = ecranOperation.getText()+plus.getText();
    		ecranOperation.setText(txt);
    		nombre1 = Double.parseDouble(ecranOperation.getText());
    		operateur = "+";
    	}
    	@FXML
    	public void sous(ActionEvent event) {
    		String txt = ecranOperation.getText()+moins.getText();
    		ecranOperation.setText(txt);
    		nombre1 = Double.parseDouble(ecranOperation.getText());
    		operateur = "-";
    	}
    	@FXML
    	public void multi(ActionEvent event) {
    		String txt = ecranOperation.getText()+mult.getText();
    		ecranOperation.setText(txt);
    		nombre1 = Double.parseDouble(ecranOperation.getText());
    		operateur = "*";
    	}
    	@FXML
    	public void divi(ActionEvent event) {
    		String txt = ecranOperation.getText()+div.getText();
    		ecranOperation.setText(txt);
    		nombre1 = Double.parseDouble(ecranOperation.getText());
    		operateur = "/";
    	}
    	@FXML
    	public void negatif(ActionEvent event) {
    		Double pm = Double.parseDouble(ecranOperation.getText());
    		pm*=(-1);
    		ecranOperation.setText(String.valueOf(pm));
     
     
    	}
    	@FXML
    	public void supprimer(ActionEvent event) {
    		String del = null;
    		if(ecranOperation.getText().length()>0) {
    			StringBuilder f = new StringBuilder(ecranOperation.getText());
    			f.deleteCharAt(ecranOperation.getText().length()-1);
    			del = f.toString();
    			ecranOperation.setText(del);
     
    		}
     
     
    	}
    	@FXML
    	public void clr(ActionEvent event) {
    		ecranOperation.setText("");
    		ecranResultat.setText("");
    	}
     
    	@FXML
    	public void result(ActionEvent event) {
     
    		nombre2 = Double.parseDouble(ecranOperation.getText());
    		if (operateur == "+") {
    			resultat = nombre1 + nombre2;
    			ecranResultat.setText(String.valueOf(resultat));
    			//ecranOperation.setText(String.valueOf(resultat));
     
    		}else if (operateur == "-") {
    			resultat = nombre1 - nombre2;
    			ecranResultat.setText(String.valueOf(resultat));
    			//ecranOperation.setText(String.valueOf(resultat));
     
    		}else if (operateur == "*") {
    			resultat = nombre1 * nombre2;
    			ecranResultat.setText(String.valueOf(resultat));
    			//ecranOperation.setText(String.valueOf(resultat));
     
    		}else if (operateur == "/") {
    			resultat = nombre1 / nombre2;
    			ecranResultat.setText(String.valueOf(resultat));
    			//ecranOperation.setText(String.valueOf(resultat));
     
    		}
    	}
    }

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 899
    Billets dans le blog
    54
    Par défaut
    On a que le code du contrôleur. Quelle méthode est associée au bouton "=" dans le FXML ? S'il s'agit de la méthode result(), je te rapelle que tu peux tout simplement mettre un breakpoint (voir comment faire dans ton IDE) dans cette méthode et vérifier qu'elle est appelée et ce qu'elle calcule en exécutant ton programme en mode débug.
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  3. #3
    Nouveau candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Septembre 2024
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Septembre 2024
    Messages : 2
    Par défaut Réponse
    Merci. La méthode contrôleur est aussi résultat. Dans le scène builder j'ai associé la méthode résultat au bouton "=" !
    J'ai fait une remarque : c'est quand je mets 2 textfields et que je veux que le résultat s'affiche sur la 2eme textfild que l'erreur apparaît mais si je fais juste une textfields tout passe comme il faut. Merci

  4. #4
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 899
    Billets dans le blog
    54
    Par défaut
    Et donc dans le FXML (qu'on a toujours pas vu), le 2nd TextField a la bonne fx:id ? Également tu ne nous as pas montré le bout de code qui charge le FXML et son contrôleur.
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

Discussions similaires

  1. Erreur sur une fonction avec des paramètres
    Par Elois dans le forum PostgreSQL
    Réponses: 2
    Dernier message: 05/05/2004, 21h00
  2. [VBS] Erreur sur "AddWindowsPrinterConnection"
    Par Admin dans le forum VBScript
    Réponses: 5
    Dernier message: 27/03/2004, 16h15
  3. Erreur sur serveur lié
    Par k-lendos dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 18/03/2004, 15h21
  4. []Erreur sur second emploi collection binding
    Par jacma dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 08/03/2004, 18h02
  5. Erreur sur le TNSListener après installation de 9iAS
    Par Patmane dans le forum Installation
    Réponses: 4
    Dernier message: 04/02/2004, 11h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo