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
|
if (e.getSource() == jMenuFichier_ItemOuvrir) {
try {
JFileChooser chooser = new JFileChooser();
int choix = chooser.showOpenDialog(null);
//choix correspond à la liste suivante
//* JFileChooser.APPROVE_OPTION
//* JFileChooser.CANCEL_OPTION
//* JFileCHooser.ERROR_OPTION
if (choix == 0) {
File f = chooser.getSelectedFile();
ObjectInputStream in = new ObjectInputStream(
new FileInputStream(f));
try {
fenetre.setGroupeOnglets((JTabbedPane) in.readObject());// Lecture de l'objet
fenetre.repaint();
fenetre.validate();
} catch (ClassNotFoundException ex) {
Logger.getLogger(Menu.class.getName()).log(Level.SEVERE, null, ex);
}
in.close();
}
} catch (IOException ioe) {
System.out.println(ioe);
}
}
if (e.getSource() == jMenuFichier_ItemSauver) {
try {
JFileChooser chooser = new JFileChooser();
int choix = chooser.showSaveDialog(null);
//choix correspond à la liste suivante
//* JFileChooser.APPROVE_OPTION
//* JFileChooser.CANCEL_OPTION
//* JFileCHooser.ERROR_OPTION
if (choix == 0) {
File f = chooser.getSelectedFile();
f.createNewFile();
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(f));
out.writeObject(fenetre.getGroupeOnglets()); // Écriture de l'objet
out.close();
}
} catch (IOException ioe) {
System.out.println(ioe);
}
} |
Partager