+ 2

Search for single elements in Java

Hello, I currently struggle to filter single elements from a JList. I have to program a telephone book for my professor and already managed to create a new telephone book as well as loading and saving contacts via JFileChooser. I did it like this. //Serialize Data:-------------------------------------------------------------------------------------------------------------- public void saveData() throws IOException, ClassNotFoundException{ //Umwandlung des Objekts in Sequenz von Bytes zum Speichern int saveFile = fcS.showSaveDialog(this); if(saveFile == JFileChooser.APPROVE_OPTION) { FileOutputStream fileOut = new FileOutputStream(fcS.getSelectedFile().getAbsolutePath()); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(telefonbuch); out.close(); out.flush(); fileOut.close(); System.out.println("Serialized data is saved in"+(fcS.getSelectedFile().getAbsolutePath())); }} //DeSerialize Data:-------------------------------------------------------------------------------------------------------------------- @SuppressWarnings("unchecked") public void loadData() throws IOException, ClassNotFoundException, ClassCastException{ //zurück zu Ursprungsform zum Laden??? try { if (fcL.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { FileInputStream fileIn = new FileInputStream(fcL.getSelectedFile().getAbsolutePath()); ObjectInputStream in = new ObjectInputStream(fileIn); telefonbuch = (ArrayList<Kontakt>)in.readObject(); System.out.println(telefonbuch.toString()); System.out.println("deserialized data is loaded from"+ fcL.getSelectedFile().getAbsolutePath()); in.close(); fileIn.close(); }}catch (IOException i) { i.printStackTrace(); return; }catch (ClassNotFoundException c) { c.printStackTrace(); return; } } Furthermore I`m also able display my created contacts by means of a JSplitPane. However, my professor wants

2nd Jul 2018, 3:13 PM
Lexerades
Lexerades - avatar
1 Réponse