next up previous contents index
Next: Eigenschaftseditoren Up: Programmbeispiele Previous: Eingeschraenkte Eigenschaften: Thermometer.javaConstrainer.java,

Serialisierung

  Storage.java
import java.io.*;
import java.awt.*;
import java.awt.event.*;

public class Storage extends Button{
    protected String dateiname;
    protected boolean mode;
    public static final boolean save = true;
    public static final boolean restore = false;
    
    public Storage(){
        mode = save;
        dateiname = new String("Storage.tmp");
        setLabel("Wurst");
        addActionListener(new MyListener());
    }
    class MyListener implements ActionListener{
        //ueberschreiben
        public void actionPerformed(ActionEvent e){
            if (mode) save(); else restore();
        }
    }
    // ne paar Zugriffmethoden
    public String getDateiname(){return dateiname;}
    public void setDateiname(String s){dateiname = s;}
    public boolean getMode(){return mode;}
    public void setMode(boolean b){mode=b;}

    private void save(){
       try{
            FileOutputStream fos = new FileOutputStream(dateiname);
            ObjectOutputStream s = new ObjectOutputStream(fos);
            s.writeObject(getLabel());
            s.flush();
       }catch (Exception e){System.out.println(e);}
    }
    private void restore(){
       try{
           FileInputStream fis = new FileInputStream(dateiname);
           ObjectInputStream s = new ObjectInputStream(fis);
           setLabel((String)s.readObject());
       }catch (Exception e){System.out.println(e);}
    }
}


next up previous contents index
Next: Eigenschaftseditoren Up: Programmbeispiele Previous: Eingeschraenkte Eigenschaften: Thermometer.javaConstrainer.java,

mail@axel-faltin.de