I have a JTabbedPane containing 7 tabs each tab contains a class extending JPanel, what I need is if I change in any tab and save to a file, the changes made could be used in the other tabs without closing the program and running it again
I added the tabs to the JTabbedPane
tp.addTab(" Etudiant ", new Etudiant());
tp.addTab(" Enseignant ", new Enseignant());
tp.addTab(" Cours ", new Cours());
tp.addTab(" Groupes ", new Groupe());
tp.addTab(" Inscription ", new Inscription());
tp.addTab(" Horaires ", new Horaires());
tp.addTab(" Resultats ", new Resultats());
tp.addTab(" Divers ", new Divers());
then I created a change listener to read from a file each time I choose a tab, I need to use the ArrayList read from the file in the class(of each tab)
tp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
switch (tp.getSelectedIndex()) {
case 3:
if (file3.length() > 0) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Cours.out"));
listCours = (ArrayList) ois.readObject();
System.out.println("cours read");
System.out.println(listCours);
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
listCours = new ArrayList();
}
if (file4.length() > 0) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Inscriptions.out"));
listIns = (ArrayList) ois.readObject();
System.out.println("insc read");
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
listIns = new ArrayList();
}
break;
case 4:
if (file.length() > 0) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Etudiants.out"));
listEtud = (ArrayList) ois.readObject();
System.out.println("etud read");
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
listEtud = new ArrayList();
}
if (file2.length() > 0) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Groupes.out"));
listGroupes = (ArrayList) ois.readObject();
System.out.println("group read");
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
listGroupes = new ArrayList();
}
if (file3.length() > 0) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Cours.out"));
listCours = (ArrayList) ois.readObject();
System.out.println("cours read");
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
listCours = new ArrayList();
}
break;
case 5:
break;
case 6:
break;
default:
break;
}
}
});