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

36 lines
1.2 KiB
Java
Raw Permalink Normal View History

2024-12-09 11:53:11 +01:00
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class memoire{
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();
}
}