62 lines
1.7 KiB
Java
62 lines
1.7 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, 10, 10));
|
||
|
|
||
|
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);
|
||
|
|
||
|
f.setVisible(true);
|
||
|
Fond.restoreLastSettings(f);
|
||
|
f.addWindowListener(new CloseListener());
|
||
|
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
Color c = new Color(fl.readInt());
|
||
|
|
||
|
f.setSize(x, y);
|
||
|
f.setLocation(w, h);
|
||
|
f.setBackground(c);
|
||
|
|
||
|
|
||
|
try {
|
||
|
fl.close();
|
||
|
} catch (IOException e) {
|
||
|
System.out.println(e);
|
||
|
}
|
||
|
} catch (IOException e) {
|
||
|
System.out.println(e);
|
||
|
}
|
||
|
} catch (IOException e) {
|
||
|
System.out.println(e);
|
||
|
}
|
||
|
}
|
||
|
}
|