58 lines
1.6 KiB
Java
58 lines
1.6 KiB
Java
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);
|
|
}
|
|
}
|
|
} |