Slt, voici mon projet qui me pose pas mal de problème.
Je veux ouvrir un fichier dans ma méthode et affiché le contenu du fichier mais à chaque essai j'ai des exceptions du type java.io.EOFException.
voici le code:
package diegoproj;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import diegoproj.Ajoute;
import diegoproj.search;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.Serializable;
import java.util.Vector;
public class Fentr extends JFrame implements ActionListener,Serializable{
JPanel panel;
JMenuBar bare=new JMenuBar();
JMenu menu1,menu2,menu3;
JMenuItem item1,item2,item3;
JLabel l1,l2,l3,l4,l5,l6,copy;
JButton b,b1;
static JList list;
JTextField t1,t2,t3,t4,t5;
static Fentr acc;
JMenuItem rech,nouv,quit,enreg;
static Vector repert=new Vector();
boolean lect=false;
static Fichier f=new Fichier();
public Fentr(String titre) throws IOException, ClassNotFoundException {
setTitle(titre);
setSize(600,500);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
rech= new JMenuItem("Contact" );
panel=new JPanel();
menu1=new JMenu("Fichier" );
menu2=new JMenu("Recherche" );
menu2.add(rech);
rech.addActionListener(this);
menu3=new JMenu("Aide" );
nouv=new JMenuItem("Nouveau Contact" );
menu1.add(nouv);
nouv.addActionListener(this);
menu1.addSeparator();
enreg=new JMenuItem("Enregistrer" );
enreg.addActionListener(this);
menu1.add(enreg);
menu1.addSeparator();
quit=new JMenuItem("Quitter" );
quit.addActionListener(this);
menu1.add(quit);
bare.add(menu1);
bare.add(menu2);
bare.add(menu3);
panel.setLayout(null);
Font font=new Font("Courier",Font.BOLD,20);
panel.setFont(font);
l1=new JLabel("LISTE DES CONTACTS" );
l1.setBounds(25,8,150,30);
panel.add(l1);
b=new JButton("SUPPRIMER" );
b.setBounds(40,390,110,30);
b1=new JButton("Modifier" );
b1.setBounds(380,210,90,30);
b1.addActionListener(this);
panel.add(b1);
panel.add(b);
setJMenuBar(bare);
list=new JList();
if(f.ouvrir("lecture" )==true){
repert=(Vector)f.lire();
f.fermer();
}
System.out.println(repert.size());
list.setListData(repert);
list.setVisibleRowCount(5);
list.setFixedCellHeight( 15 );
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectionForeground(Color.CYAN);
list.addListSelectionListener(new ListSelectionListener(){
public void valueChanged( ListSelectionEvent e){
for(int i=0;i<list.getSelectedValues().length;i++)
{
String val=(String) list.getSelectedValues()[i];
int j=list.getSelectedIndex();
t1.setText(val);
}
}
});
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setPreferredSize(new Dimension(200,100));
scrollPane.setBounds(15,40,155,320);
panel.add(scrollPane);
t1=new JTextField();
t1.setBounds(300,70,100,25);
t2=new JTextField();
t2.setBounds(300,100,150,25);
t3=new JTextField();
t3.setBounds(300,130,250,25);
t4=new JTextField();
t4.setBounds(300,160,250,25);
t5=new JTextField();
t5.setBounds(380,36,30,25);
t1.setEditable(false);
t2.setEditable(false);
t3.setEditable(false);
t4.setEditable(false);
t5.setEditable(false);
panel.add(t1);
panel.add(t2);
panel.add(t3);
panel.add(t4);
panel.add(t5);
l2=new JLabel("Nom:" );
l2.setBounds(235,70,300,25);
l3=new JLabel("Prenom:" );
l3.setBounds(235,100,300,25);
l4=new JLabel("Téléphone:" );
l4.setBounds(235,130,300,25);
l5=new JLabel("E-mail:" );
l5.setBounds(235,160,300,25);
l6=new JLabel("Contact N°:" );
l6.setBounds(320,30,100,30);
copy=new JLabel("Copyright 2009\\Diego & Djim\\ucao/uub/esti2" );
copy.setBounds(330,410,300,30);
copy.updateUI();
panel.add(copy);
panel.add(l6);
panel.add(l2);
panel.add(l3);
panel.add(l4);
panel.add(l5);
getContentPane().add(panel);
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
}catch(Exception e){
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(Fentr.this);
}
public static void main(String[] args)throws IOException, ClassNotFoundException {
acc=new Fentr("Accueil" );
acc.setVisible(true);
}
}
Si nécessaire je vous fairé parvenir le code de mon fichier.
Merci d'avance!