Prbleme avec bouton radio

Résolu
fatimazahrazaidi Messages postés 29 Date d'inscription samedi 12 mai 2007 Statut Membre Dernière intervention 19 décembre 2009 - 18 déc. 2009 à 00:08
kirua12 Messages postés 1155 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 29 avril 2011 - 20 déc. 2009 à 12:21
bonjour,
j'ai un problème de retourner la valeur d un bouton radio lorsque je clique sur ok elle s enregistre pas dans un fichier texte
voici le programme :

public void test1() throws IOException {
JPanel p = (JPanel)getContentPane(); final JButton f1=new JButton("save");
final Checkbox che1=new Checkbox("F");
enregistrer enr=new enregistrer();
enr.setChe1(che1.getLabel());
enr.getChe1();
f1.addActionListener(enr);
p.add("North",che1);
p.add("South",f1);
pack();
setSize(500, 200);
etDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
setResizable(true);
}

et vois la classe enregistrer :

public class enregistrer implements ActionListener {
String che1;

public void actionPerformed(ActionEvent arg0) {
FileWriter f=null;
try {
f = new FileWriter("test.txt", true);
f.write(getChe1()+"\r");
}
catch (IOException e) { }
try {
f.close();
} catch (IOException e) {
e.printStackTrace();
}

}

public String getChe1() {
return che1;
}

public void setChe1(String che1) {
this.che1 = che1;
}

}

merci d'avance

4 réponses

kirua12 Messages postés 1155 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 29 avril 2011 7
18 déc. 2009 à 10:07
Salut,

j'ai testé ton code et j'ai bien la valeur 'F' dans le fichier. Il est où le pb ?
3
fatimazahrazaidi Messages postés 29 Date d'inscription samedi 12 mai 2007 Statut Membre Dernière intervention 19 décembre 2009 2
18 déc. 2009 à 20:26
salut
est ce que tu a ajouté des modifications
par ce que moi j en ai pas eu la valeur F dans le fichier test.txt

merci pour ta réponse

voila mon code complet :
import java.awt.Checkbox;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class TestF extends JFrame{

public void test1() throws IOException {
JPanel p = (JPanel)getContentPane();
final JButton f1=new JButton("save");
final Checkbox che1=new Checkbox("F");
enregistrer enr=new enregistrer();
enr.setChe1(che1.getLabel());
enr.getChe1();
f1.addActionListener(enr);
p.add("North",che1);
p.add("South",f1);
pack();
setSize(500, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
setResizable(true);
}

public TestF() throws IOException {
test1();

}

public static void main(String[] args) throws IOException {
new TestF();


}

}


et la deuxième classe enregistrer

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.io.IOException;


public class enregistrer implements ActionListener {
String che1;

public void actionPerformed(ActionEvent arg0) {
FileWriter f=null;
try {
f = new FileWriter("test.txt", true);
f.write(getChe1()+"\r");
}
catch (IOException e) { }
try {
f.close();
} catch (IOException e) {
e.printStackTrace();
}

}

public String getChe1() {
return che1;
}

public void setChe1(String che1) {
this.che1 = che1;
}

}
3
fatimazahrazaidi Messages postés 29 Date d'inscription samedi 12 mai 2007 Statut Membre Dernière intervention 19 décembre 2009 2
19 déc. 2009 à 18:12
salut;
pourquoi y a pas de reponse ??????
3
kirua12 Messages postés 1155 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 29 avril 2011 7
20 déc. 2009 à 12:21
non, je n'ai fait aucune modification (copier-coller direct) et j'ai bien la valeur 'F' dans le fichier
0
Rejoignez-nous