Besoin d'aide pour actionPerformed(ActionEvent evt)

developvbdebut Messages postés 476 Date d'inscription samedi 14 août 2004 Statut Membre Dernière intervention 2 juin 2012 - 22 mai 2006 à 10:13
kaloway Messages postés 358 Date d'inscription jeudi 24 octobre 2002 Statut Membre Dernière intervention 13 avril 2020 - 22 mai 2006 à 20:25
Bonjour tout le monde

Je m'initie a actionPerformed(ActionEvent evt)

Voici le code.

public void actionPerformed(ActionEvent evt) {



mode.getState();





Calcul cal = new Calcul();



if ("convert".equals(evt.getActionCommand() && (radio1.getState()||radio2.getState())))
{
float s = Float.valueOf(somme.getText());





resultat.getText(cal.convertir(s,mode));



}




 



if("quit".equals(evt.getActionCommand()))
{



System.exit(0);





}





}



Voici les erreurs.

C:\Documents and Settings\vincent1\Bureau\conv>javac Compostconv.java
Compostconv.java:48: addActionListener(java.awt.event.ActionListener) in javax.s
wing.JTextField cannot be applied to (Compostconv)
        somme.addActionListener(this);
             ^
Compostconv.java:63: addActionListener(java.awt.event.ActionListener) in javax.s
wing.JTextField cannot be applied to (Compostconv)
        resultat.addActionListener(this);
                ^
Compostconv.java:74: cannot find symbol
symbol  : method addActionListener(Compostconv)
location: class java.awt.Checkbox
        radio1.addActionListener(this);
              ^
Compostconv.java:82: cannot find symbol
symbol  : method addActionListener(Compostconv)
location: class java.awt.Checkbox
        radio2.addActionListener(this);
              ^
Compostconv.java:91: addActionListener(java.awt.event.ActionListener) in javax.s
wing.AbstractButton cannot be applied to (Compostconv)
        convert.addActionListener(this);
               ^
Compostconv.java:97: addActionListener(java.awt.event.ActionListener) in javax.s
wing.AbstractButton cannot be applied to (Compostconv)
        quit.addActionListener(this);
            ^
Compostconv.java:111: cannot find symbol
symbol  : variable mode
location: class Compostconv
mode.getState();
^
Compostconv.java:116: cannot find symbol
symbol  : variable radio1
location: class Compostconv
if ("convert".equals(evt.getActionCommand() && (radio1.getState()||radio1.getSta
te())))
                                              
Compostconv.java:116: cannot find symbol
symbol  : variable radio1
location: class Compostconv
if ("convert".equals(evt.getActionCommand() && (radio1.getState()||radio1.getSta
te())))
                                                                 
Compostconv.java:116: operator && cannot be applied to java.lang.String,boolean
if ("convert".equals(evt.getActionCommand() && (radio1.getState()||radio1.getSta
te())))
                                          
Compostconv.java:118: cannot find symbol
symbol  : variable somme
location: class Compostconv
float s = Float.valueOf(somme.getText());
                        ^
Compostconv.java:121: cannot find symbol
symbol  : variable mode
location: class Compostconv
resultat.getText(cal.convertir(s,mode));
                                 ^
Compostconv.java:121: cannot find symbol
symbol  : variable resultat
location: class Compostconv
resultat.getText(cal.convertir(s,mode));
^
13 errors

Je souhaiterais qu'on m'explique comment recuperer les composants dans actionPerformed(ActionEvent evt) car là je suis perdus.

Pourriez vous m'aider svp, c'est URGENT

Merci

Cordialement

A bientôt

5 réponses

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
22 mai 2006 à 10:20
As-tu essayé un evt.getSource();

_
Avant de poster dans le forum,
prière d'aller lire ceci :
http://www.codes-sources.com/reglement.aspx
<s></s>
0
developvbdebut Messages postés 476 Date d'inscription samedi 14 août 2004 Statut Membre Dernière intervention 2 juin 2012 1
22 mai 2006 à 10:37
Re

J'ai cherché sur le net, les explication sont assés vague.

De plus étend débutant mon vucabulaire en java est minime.

Je veux juste que m'explique clairement comment fonctionne  actionPerformed(ActionEvent evt)

avec evt.getSource(); c'est la meme chose il ne reconnait pas les composants.

Merci

Cordialement

A bientôt
0
tucobouch Messages postés 194 Date d'inscription vendredi 17 février 2006 Statut Membre Dernière intervention 1 mai 2009 50
22 mai 2006 à 16:33
Voir mon tuto :

ici

- [TucoBouch] -
0
developvbdebut Messages postés 476 Date d'inscription samedi 14 août 2004 Statut Membre Dernière intervention 2 juin 2012 1
22 mai 2006 à 17:27
bonsoir tout le monde



import javax.swing.*;
import java.awt.*;
import java.awt.Color.*;
import java.awt.event.*;




 





public class Compostconv extends JPanel
{



CheckboxGroup groupradio;
Checkbox radio1;
Checkbox radio2;





JTextField somme;
JTextField resultat;



JButton convert;
JButton quit;




 



public Compostconv()



{




 




 



 




 





 JLabel titre = new JLabel("Mon convertisseur");
 this.add(titre); 
 titre.setForeground(Color.red);



 Font tritrefont = titre.getFont();
 tritrefont = tritrefont.deriveFont(Font.BOLD).deriveFont(16f);
 titre.setFont(tritrefont);
 





 JLabel som= new JLabel("inserer la somme a convertir");
 
 som.setForeground(Color.blue);
 this.add(som);
 
 Font sommefont = som.getFont();
 sommefont = sommefont.deriveFont(Font.BOLD).deriveFont(12f);
 som.setFont(sommefont);



 somme = new JTextField(10);
 somme.addActionListener(this);
 this.add(somme);
 
 



 JLabel result= new JLabel("Résultat");
 this.add(result);



 result.setForeground(Color.blue);
 Font resultfont = result.getFont();
 resultfont = resultfont.deriveFont(Font.BOLD).deriveFont(12f);
 result.setFont(resultfont);





 resultat = new JTextField(10);
 resultat.addActionListener(this);
 this.add(resultat);




 





 radio1 = new Checkbox("Convertir en eurro",groupradio,true);
 radio1.addActionListener(this);
 this.add(radio1);
 radio1.setForeground(Color.magenta);
 Font eurrofont = radio1.getFont();
 eurrofont = eurrofont.deriveFont(Font.BOLD).deriveFont(12f);





 radio2 = new Checkbox("Convertir en france",groupradio,false);
 radio2.addActionListener(this);
 this.add(radio2);
 radio2.setForeground(Color.magenta);
 Font francfont = radio2.getFont();
 francfont = francfont.deriveFont(Font.BOLD).deriveFont(12f);



 
 
 convert = new JButton("Convertir");
 convert.addActionListener(this);
 this.add(convert);



 



 quit = new JButton("Quitter");
 quit.addActionListener(this);
 this.add(quit);





 





 



}





public void actionPerformed(ActionEvent evt) {





boolean mode;




 





Calcul cal = new Calcul();



if ("convert".equals(evt.getActionCommand()) && (radio1.getState()||radio2.getState()))
{
float s = Float.valueOf(somme.getText());




 





resultat.getText(cal.convertir(s,mode));



}




 



if("quit".equals(evt.getActionCommand()))
{



System.exit(0);





}





}




 



}


 


Les erreur qu'il reste:

C:\Documents and Settings\vincent1\Bureau\conv>javac Compostconv.java
Compostconv.java:60: addActionListener(java.awt.event.ActionListener) in javax.s
wing.JTextField cannot be applied to (Compostconv)
        somme.addActionListener(this);
            
Compostconv.java:75: addActionListener(java.awt.event.ActionListener) in javax.s
wing.JTextField cannot be applied to (Compostconv)
        resultat.addActionListener(this);
               
Compostconv.java:82: cannot find symbol
symbol  : method addActionListener(Compostconv)
location: class java.awt.Checkbox
        radio1.addActionListener(this);
             
Compostconv.java:90: cannot find symbol
symbol  : method addActionListener(Compostconv)
location: class java.awt.Checkbox
        radio2.addActionListener(this);
             
Compostconv.java:99: addActionListener(java.awt.event.ActionListener) in javax.s
wing.AbstractButton cannot be applied to (Compostconv)
        convert.addActionListener(this);
              
Compostconv.java:105: addActionListener(java.awt.event.ActionListener) in javax.
swing.AbstractButton cannot be applied to (Compostconv)
        quit.addActionListener(this);
           
Compostconv.java:134: convertir(java.lang.Boolean,float) in Calcul cannot be app
lied to (float,boolean)
resultat.getText(cal.convertir(s,mode));
                   
7 errors

Je souhaiterai savoir ce que demande java.au niveau des compsants, car la je sui perdu.

cette syntaxe quit".equals(evt.getActionCommand()) revient au même je crois.

il ne reste qu'une erreur dans le actionPerformed(ActionEvent evt)


Merci

Cordialement

A bientôt
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
kaloway Messages postés 358 Date d'inscription jeudi 24 octobre 2002 Statut Membre Dernière intervention 13 avril 2020
22 mai 2006 à 20:25
bonsoir

1)les ecouteurs d'évènements qu'on associe aux jtextfields sont des keylistener (ecoute  frappe  de clavier) et non des actionlisteners.
dans ton application, il est unutile de mettre des keylistners.

2)remplace les jcheckboxs par des jradiobuttons. la différence entre es jcheckboxs et les jradiobuttons est que dans un cas tu peux avoir plusieurs jcheckboxs de coché alors que tu peux avoir un seul jradiobuttons de selectionné. il faut un associé un jbuttongroup aux jradiobuttons.

3)pour connaitre dans quel mode (franc, euro) que tu es on va regardé l'etat de tes jradiobuttons avec la méthode isSelected() qui retourne un bolléen.

4) inverse s et mode dans  cal.convertir(s,mode)

avec tout ce que je t'ai dit tu verras plus claire.
0
Rejoignez-nous