85 lines
1.8 KiB
Java
85 lines
1.8 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import java.io.*;
|
|
|
|
public class MainFond {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
int w=1000;
|
|
int h=1000;
|
|
int x = 10;
|
|
int y = 10;
|
|
int oldColor = 0;
|
|
try
|
|
{
|
|
FileInputStream fis = new FileInputStream("./save.bin");
|
|
DataInputStream dis = new DataInputStream(fis);
|
|
w = dis.readInt();
|
|
h = dis.readInt();
|
|
x = (int) dis.readDouble();
|
|
y = (int) dis.readDouble();
|
|
oldColor = dis.readInt();
|
|
dis.close();
|
|
}
|
|
catch(IOException e)
|
|
{
|
|
System.out.println("probleme de lecture");
|
|
}
|
|
|
|
|
|
JFrame fenetre = new JFrame();
|
|
fenetre.setSize(w, h);
|
|
fenetre.setLocation(x, y);
|
|
|
|
Fond tamere = new Fond();
|
|
switch(oldColor)
|
|
{
|
|
case 1:
|
|
tamere.setBackground(Color.BLUE);
|
|
break;
|
|
case 2:
|
|
tamere.setBackground(Color.RED);
|
|
break;
|
|
case 3:
|
|
tamere.setBackground(Color.GREEN);
|
|
break;
|
|
}
|
|
|
|
fenetre.add(tamere, BorderLayout.CENTER);
|
|
|
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
fenetre.addWindowListener(new WindowAdapter() {
|
|
@Override
|
|
public void windowClosing(WindowEvent e)
|
|
{
|
|
int w = fenetre.getSize().width;
|
|
int h = fenetre.getSize().height;
|
|
double px = fenetre.getLocation().getX();
|
|
double py = fenetre.getLocation().getY();
|
|
try
|
|
{
|
|
FileOutputStream fos = new FileOutputStream("./save.bin");
|
|
DataOutputStream dos = new DataOutputStream(fos);
|
|
dos.writeInt(w);
|
|
dos.writeInt(h);
|
|
dos.writeDouble(px);
|
|
dos.writeDouble(py);
|
|
dos.writeInt(tamere.etat);
|
|
dos.close();
|
|
}
|
|
catch(IOException Err)
|
|
{
|
|
System.out.println("probleme de lecture");
|
|
}
|
|
fenetre.dispose();
|
|
}
|
|
});
|
|
|
|
|
|
fenetre.setVisible(true);
|
|
}
|
|
} |