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
| private String lireLigne(int lineNumber){
String line = "";
String file = "client.txt";
LineNumberReader lnr = null;
int i = 0;
try{
//construction de l'objet LineNumberReader
lnr = new LineNumberReader(new FileReader(file));
while (i < lineNumber) {
line = lnr.readLine();
i++;
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
//close de bufferedwriter
try {
if (lnr != null) {
lnr.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return line;
}
int ligne = 1;
private JButton getBtnNext() {
if (btnNext == null) {
btnNext = new JButton("Suivant");
btnNext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String line = lireLigne(ligne);
if (line == null){ //si on est à la fin du fichier
ligne = 1; //on revient au début du fichier
line = lireLigne(ligne);
}
String tab[] = line.split(";");
textField_Matricule.setText(tab[0]);
textField_Identifiant.setText(tab[1]);
textField_Nom.setText(tab[2]);
textField_Prenom.setText(tab[3]);
textField_Tel.setText(tab[4]);
textField_Mail.setText(tab[5]);
ligne++;
}
});
btnNext.setBounds(177, 267, 89, 23);
}
return btnNext;
} |