APL/APL2.1/TP13/Memoire/Fond.java

58 lines
1.6 KiB
Java
Raw Permalink Normal View History

2022-05-16 17:29:36 +02:00
import java.awt.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import javax.swing.*;
public class Fond {
public static void main(String[] args) {
JFrame f = new JFrame("Fond");
f.setSize(200, 200);
f.setLocation(100, 100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(1, 3));
JButton b1 = new JButton("Jaune");
JButton b2 = new JButton("Cyan");
JButton b3 = new JButton("Magenta");
Observer observer = new Observer();
b1.addActionListener(observer);
b2.addActionListener(observer);
b3.addActionListener(observer);
f.add(b1);
f.add(b2);
f.add(b3);
Fond.restoreLastSettings(f);
f.addWindowListener(new CloseListener());
f.setVisible(true);
}
public static void restoreLastSettings(JFrame f) {
try (ObjectInputStream fl = new ObjectInputStream(new FileInputStream("save.dat"))) {
try {
int x = fl.readInt();
int y = fl.readInt();
int w = fl.readInt();
int h = fl.readInt();
f.setSize(x, y);
f.setLocation(w, h);
try {
fl.close();
} catch (IOException e) {
System.out.println(e);
}
} catch (IOException e) {
System.out.println(e);
}
} catch (IOException e) {
System.out.println(e);
}
}
}