DEV/DEV2.1/TP7/MainFond.java

85 lines
1.8 KiB
Java
Raw Normal View History

2023-04-27 11:24:21 +02:00
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
2023-05-09 11:23:33 +02:00
import java.io.*;
2023-04-27 11:24:21 +02:00
public class MainFond {
public static void main(String[] args) {
2023-05-09 11:23:33 +02:00
int w=1000;
int h=1000;
int x = 10;
int y = 10;
int oldColor = 0;
2023-04-27 11:24:21 +02:00
try
{
FileInputStream fis = new FileInputStream("./save.bin");
DataInputStream dis = new DataInputStream(fis);
2023-05-09 11:23:33 +02:00
w = dis.readInt();
h = dis.readInt();
x = (int) dis.readDouble();
y = (int) dis.readDouble();
oldColor = dis.readInt();
dis.close();
2023-04-27 11:24:21 +02:00
}
catch(IOException e)
{
System.out.println("probleme de lecture");
}
JFrame fenetre = new JFrame();
2023-05-09 11:23:33 +02:00
fenetre.setSize(w, h);
fenetre.setLocation(x, y);
2023-04-27 11:24:21 +02:00
Fond tamere = new Fond();
2023-05-09 11:23:33 +02:00
switch(oldColor)
2023-04-27 11:24:21 +02:00
{
2023-05-09 11:23:33 +02:00
case 1:
tamere.setBackground(Color.BLUE);
break;
case 2:
tamere.setBackground(Color.RED);
break;
case 3:
tamere.setBackground(Color.GREEN);
break;
2023-04-27 11:24:21 +02:00
}
2023-05-09 11:23:33 +02:00
2023-04-27 11:24:21 +02:00
fenetre.add(tamere, BorderLayout.CENTER);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
2023-05-09 11:23:33 +02:00
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();
}
});
2023-04-27 11:24:21 +02:00
fenetre.setVisible(true);
}
}