Developpement/23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/memory.java

36 lines
1.2 KiB
Java

import javax.swing.*;
import java.awt.*;
import java.io.*;
public class memoire extends implement{
public void windowOpened(WindowEvent event){
Window window = event.getWindow();
Point defaultLocation = new Point(0, 0);
Dimension defaultDimension = Dimension(400, 400);
try(ObjectInputStream input = new ObjectInputStream(new FileInputStream("/tmp/memoire/save.bin"))){
Object location = input.readObject();
Object size = input.readObject();
if(size instanceof Point){
defaultLocation = (Point)location;
}
if(size instanceof Dimension){
defaultDimension = (Dimension)size;
}
}catch(IOException | ClassNotFoundException e){
}
window.setLocation(defaultLocation);
window.setSize(defaultDimension);
}
public void windowClosing(WindowEvent event){
Window window = event.getWindow();
try(ObjectOutputStream input = new ObjectOutputStream(new FileOutputStream("/tmp/memoire/save.bin"))){
input.writeObject(window.getLocation());
input.writeObject(window.getSize());
}catch(IOException | ClassNotFoundException e){
System.out.println(e.getMessage);
}
}
public memoire(){
super();
}
}