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

Interfaces Graphiques en Java Discussion :

Action sur le bouton calculer


Sujet :

Interfaces Graphiques en Java

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    138
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 138
    Points : 0
    Points
    0
    Par défaut Action sur le bouton calculer
    Bonjour tous le monde

    j'ai créer une application qui permet de calculer le cout totale de fabrication, mais malheureusement, j'ai une probleme avec l'affichage de résultat

    svp j'ai besoin de votre aide

    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
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
     
     
    		public class SousFenetre extends JPanel {
    				int Demandei[]  = {0, 0, 0, 0, 0}; 
    				int p = 0;
    				int CoutTotaleDePeriode[][] = new int[p][p+1];
    		        int L, M, QuantitéàProduite;
    		        int CoutFabrication;
    		        int CoutStock;
    		        int A[] = {0, 0, 0, 0, 0, 0};
    		        int f[] = {0, 0, 0, 0, 0, 0}; 
    			 	private static final int MARGIN = 10;
    				private static final long serialVersionUID = 1L;
    				private Map<String, JTextField> fieldMap = new HashMap<String, JTextField>();
    				List<Integer> listInt = new ArrayList<Integer>();
    				public final static String FIELD_INITVAR_PERIODE = "Periode";
    				public final static String FIELD_INITVAR_DEMANDEP = "demandeP";
    				JTextField DemandeP,Periode; 
    				JButton btnCalculer,btnAfficher,demandePValide,periodeValide;
    				JLabel resultatGauche;
    				JPanel p1,p2;
     
     
    				public SousFenetre() {
    					setBorder(BorderFactory.createEmptyBorder(MARGIN,MARGIN,MARGIN,MARGIN)); //  une petite bordure pour ne pas être collé au bord de la fenêtre
    					setLayout(new GridLayout(2,1,MARGIN,MARGIN)); // grille 2 x 2
    					this.setBackground(Color.LIGHT_GRAY); // Couleur de Fenetre
     
    					// ajoute des 4 panels
    					add(creerPanelHaut());
    					add(creerPanelBas());
    				}
     
    				public JPanel creerPanelHaut() {
    					p2 = creerPanelAvecTitre("Initialisation les variables :");
    					p2.setBackground(Color.LIGHT_GRAY);
    					btnCalculer = new JButton("Calculer");		
    					btnCalculer.addActionListener(new BtnCalculerListener());
    					p2.add(btnCalculer,BorderLayout.SOUTH);
    					Box hBox1 = Box.createHorizontalBox();
    			        hBox1.add(btnCalculer);
     
    					btnAfficher = new JButton("Afficher la résultat : ");
    					btnAfficher.addActionListener(new BtnCalculerListener());
    					Box hBox2 = Box.createHorizontalBox();
    			        hBox2.add(btnAfficher);
     
    			        Box vBox = Box.createHorizontalBox();
    			        vBox.add(hBox1);
    			        vBox.add(hBox2);
    			        p2.add(vBox,BorderLayout.SOUTH);
     
    			        p2.add(SaisieHPanel(), BorderLayout.CENTER);
    					return p2;
    				}
     
    				public JPanel creerPanelBas() {
    					p1 = creerPanelAvecTitre("Résultat :");
    					p1.setBackground(Color.white); // ça tu l'ajoutes (je l'avais pas mis, je ne pouvais pas savoir au moment ou j'ai posté le code que tu le voulais en blanc)
    					p1.add(SaisieBPanel(), BorderLayout.CENTER);
    					return p1;
    				}
     
    				public JPanel SaisieHPanel() {
    					JPanel panel = new JPanel();
    					panel.setBackground(Color.LIGHT_GRAY);
    					SpringLayout layout = new SpringLayout();
    					panel.setLayout(layout); 	//					panel.setLayout(new GridLayout(2,1));
     
    					JLabel PeriodeLabel = new JLabel("Le Periode        :  ");
    					panel.add( PeriodeLabel );
    					Periode = new JTextField();
    					Periode.setColumns(3);
    					fieldMap.put( FIELD_INITVAR_PERIODE, Periode );
    					panel.add(Periode);
    					periodeValide = new JButton("Validée");
    					periodeValide.addActionListener(new periodeValideListener());
    					panel.add(periodeValide);
     
    					JLabel DemandePLabel = new JLabel("Demande de Période   :  ");
    					panel.add(DemandePLabel );
    					DemandeP = new JTextField();
    					DemandeP.setColumns(3);
    					fieldMap.put( FIELD_INITVAR_DEMANDEP, DemandeP );
    					panel.add(DemandeP);
    					demandePValide = new JButton("Validée");
    				    demandePValide.addActionListener(new DemandePValideListener());
    					panel.add(demandePValide);
     
    					SpringUtilities.makeCompactGrid(panel, 2, 3, 20, 0, 20, 10);
    					return panel;
    				}
     
    				public JPanel SaisieBPanel(){
     
    					JPanel panel = new JPanel();
    					panel.setBackground(Color.white);
    					SpringLayout layout = new SpringLayout();
    					panel.setLayout(layout); 
     
    					return panel;
    				}
     
    				public JPanel creerPanelAvecTitre(String titre) {
    					JPanel panel = new JPanel();
    					panel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); // un cadre autour
    					panel.setLayout(new BorderLayout(MARGIN, MARGIN)); 
     
    					JLabel titreLabel = new JLabel(titre);// création du titre du panel
    					titreLabel.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN)); // appeler à les titres
    					panel.add(titreLabel, BorderLayout.NORTH); // texte en haut du panel
    					return panel;
    				}
     
    				public JPanel getP1() {
    					return p1;
    				}
     
    				public void setP1(JPanel p1) {
    					this.p1 = p1;
    				}
     
    				public JPanel getP2() {
    					return p2;
    				}
     
    				public void setP2(JPanel p2) {
    					this.p2 = p2;
    				}
     
    				class BtnCalculerListener implements ActionListener {
    					    public void actionPerformed(ActionEvent arg0){
    					    	float f = Float.valueOf(DemandeP.getText());  
    					    	resultatGauche.setText(String.valueOf(f));
     
    							for(int i=0; i<listInt.size();i++){
    							    Demandei[i]=listInt.get(i);
    							}
     
    							JPanel panel = new JPanel();
    							panel.add(TraitementPanel(), BorderLayout.CENTER); 
     
    					    }
    				}
     
    				public JPanel TraitementPanel(){
    					JPanel panel = new JPanel();
    					panel.setBackground(Color.LIGHT_GRAY);
    					SpringLayout layout = new SpringLayout();
    					panel.setLayout(layout);
     
    					System.out.println("\n\ti \tk \tXi \tCoutFabrication \tCoutStock \tCT");
    			        for( int periodedeproduction=1;periodedeproduction<=p-1;periodedeproduction++ ){
    			                L=0; M=0;
    			                for( int Productionàfaire=periodedeproduction+1;Productionàfaire<=p;Productionàfaire++ ){
    			                	if ( Productionàfaire == periodedeproduction+1 ) {
    			                		CoutStock=0;
    			                	} else  {
    			                		CoutStock = M+(Productionàfaire-(periodedeproduction+1))*Demandei[Productionàfaire-1];
    			                	}
    			                		QuantitéàProduite = Demandei[Productionàfaire-1]+L;
    				                    L = QuantitéàProduite;
    				                    CoutFabrication = 100 + 2*QuantitéàProduite;
     
    				                    CoutTotaleDePeriode[periodedeproduction][periodedeproduction+1] = CoutFabrication + CoutStock;
     
    				                    System.out.println("\n\t"+periodedeproduction+"\t"+Productionàfaire+"\t"+QuantitéàProduite+"\t"+CoutFabrication+"\t"+CoutStock+"\t"+CoutTotaleDePeriode[periodedeproduction][periodedeproduction+1]);
    				                    M = CoutStock;
     
    				                    f[0] =0;
    				            		A[periodedeproduction] = CoutTotaleDePeriode[periodedeproduction-1][periodedeproduction]+CoutTotaleDePeriode[periodedeproduction][periodedeproduction+1]; 
    				                    //int l =periodedeproduction-1;
    				                    //System.out.println("\t"+"f["+periodedeproduction+"]"+"+"+"CoutTotaleDePeriode["+periodedeproduction+"]["+typeDeProduction+"]"+"="+A[periodedeproduction]);
    				                    f[Productionàfaire]= A[periodedeproduction];
    				                    //System.out.println("\t"+"f["+typeDeProduction+"]"+"="+f[typeDeProduction]);
     
    				           }
    			        }
    //					 
     
     
    					return panel;
    				}
     
    				class DemandePValideListener implements ActionListener {
    				    public void actionPerformed(ActionEvent arg0){
    				    	listInt.add(Integer.valueOf(DemandeP.getText()));
    						for(Integer i : listInt){
    					    	System.out.println(i);
    					    }
    				    }
    				}
     
    				class periodeValideListener implements ActionListener {
    				    public void actionPerformed(ActionEvent arg0){
     
    				    	Periode.setEditable(false);
    				    }
    				}  
     
    				public void setField(String id, String valeur) {
    				      JTextField field = fieldMap.get(id);
    				      if ( field!=null ) field.setText(valeur);
    				}
     
    			    public String getField(String id) {
    				     JTextField field = fieldMap.get(id);
    				     if ( field!=null ) {
    					  return field.getText();
    				     } else {
    					  throw new IllegalArgumentException();
    				     }
    				 }
     
     
    				}

  2. #2
    Membre expérimenté Avatar de Ivelios
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juillet 2008
    Messages
    1 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 031
    Points : 1 540
    Points
    1 540
    Par défaut
    Bonjour,

    Peux tu être plus précis dans ton problème? Quel est l'erreur générée? A première vu je dirais que ton JLabel resultatGauche n'est jamais initialisé :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    JLabel resultatGauche = new JLabel()
    Il était une fois [...] Et ils vécurent heureux et eurent beaucoup d'enfants!

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    138
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 138
    Points : 0
    Points
    0
    Par défaut
    Mon problème, quand j'appui sur le bouton calculer, la résultat ne s'affiche pas.

    et pour le code, c'est le maximum que je veux écrire, j'ai aucun idée sur les nouveaux modification que je dois le faire et j'ai besoin de monter cette application à mes profs demain vraiment j'ai besoin d'aide

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Et dans ta console, il y a quoi, quelles sont les erreurs?

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    138
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 138
    Points : 0
    Points
    0
    Par défaut
    AUCUN error

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    dans ton actionListener, tu crée un panel TraitementPanel(), tu le rajoute dans une new JPanel() et ce dernier panneau, tu ne l'affiche nulle part. Du coup ton resultat il reste juste en mémoire, il n'atteind jamais l'écran. Ton panel doit être ajouté à un autre composant visible pour qu'il soit visible à l'écran. Par exemple à une JFrame, à un autre JPanel déjà à l'écran, etc.

    Et au passage je t'informe déjà que, sur le composant visible où tu l'ajoute (le parent), tu dois appeler après la méthode revalidate() après l'appel à add(nouveau panneau)

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    138
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 138
    Points : 0
    Points
    0
    Par défaut
    Merciii pour ton présence et ton réponse.

    Mais j'ai besoin d'un code, j'ai aucun idée sur le code, comment je doit l'ajouter ect

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    lePanneauExistantOuTuVeuxAjouter.add(tonNouveauPanneau)
    lePanneauExistantOuTuVeuxAjouter.revalidate();

  9. #9
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    138
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 138
    Points : 0
    Points
    0
    Par défaut
    En effet je crois que le probleme dans ces classe mais j'ai aucun idée pour les code que je dois ajouter

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    public JPanel creerPanelBas() {
    					p1 = creerPanelAvecTitre("Résultat :");
    					p1.setBackground(Color.white); // ça tu l'ajoutes (je l'avais pas mis, je ne pouvais pas savoir au moment ou j'ai posté le code que tu le voulais en blanc)
    					p1.add(SaisieBPanel(), BorderLayout.CENTER);
     
    					resultat = new JLabel("Résultat Pour la Periode de");// création du titre du panel
    					resultat.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN)); // appeler à les titres
    					p1.add(resultat, BorderLayout.NORTH); // texte en haut du panel
    					p1.setBackground(Color.WHITE);
     
    					return p1;
    				}

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    class BtnCalculerListener implements ActionListener {
    					    public void actionPerformed(ActionEvent arg0){
    					    	float f = Float.valueOf(DemandeP.getText());  
    					    	resultat.setText(String.valueOf(f));
     
    							for(int i=0; i<listInt.size();i++){
    							    Demandei[i]=listInt.get(i);
    							}
     
    							JPanel panel = new JPanel();
    							panel.add(TraitementPanel(), BorderLayout.CENTER); 
     
    					    }
    				}

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    class BtnAfficherListener implements ActionListener {
    				    public void actionPerformed(ActionEvent arg0){
     
     
    				    }
    				}

  10. #10
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Ben je ne sais pas comment te le dire plus que déjà dit, je ne vais pas faire le code à ta place, et de toutes façons, je ne sais pas où tu veux afficher.

    Dans ce code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    							JPanel panel = new JPanel();
    							panel.add(TraitementPanel(), BorderLayout.CENTER);
    Au lieu d'ajouter dans une nouveau JPanel qui ne sert à rien et n'est lié à rien, tu ajoute dans un JPanel déjà présent dans l'interface...

  11. #11
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    138
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2013
    Messages : 138
    Points : 0
    Points
    0
    Par défaut
    je veux l'afficher dans public JPanel creerPanelBas() {}
    je ne sais pas ce je dois faire

Discussions similaires

  1. Action sur un bouton..Je comprends plus rien du tout!
    Par koolway dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 26/04/2006, 10h17
  2. Action sur un bouton
    Par DarkHope dans le forum AWT/Swing
    Réponses: 10
    Dernier message: 25/04/2006, 15h54
  3. Action sur un bouton
    Par brasco06 dans le forum Composants
    Réponses: 1
    Dernier message: 19/11/2005, 20h15
  4. [debutant] action sur un bouton
    Par EssaiEncore dans le forum ASP
    Réponses: 22
    Dernier message: 18/02/2005, 14h02
  5. [Flash MX] Action sur un bouton
    Par WriteLN dans le forum Flash
    Réponses: 9
    Dernier message: 20/10/2003, 14h01

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