TP
This commit is contained in:
BIN
DEV2.1/TP12/01_Memoire/FermetureFenetre.class
Normal file
BIN
DEV2.1/TP12/01_Memoire/FermetureFenetre.class
Normal file
Binary file not shown.
97
DEV2.1/TP12/01_Memoire/FermetureFenetre.java
Normal file
97
DEV2.1/TP12/01_Memoire/FermetureFenetre.java
Normal file
@@ -0,0 +1,97 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import javax.swing.*;
|
||||
|
||||
public class FermetureFenetre implements WindowListener {
|
||||
|
||||
private JPanel panneau;
|
||||
private JFrame fenetre;
|
||||
|
||||
public FermetureFenetre(JFrame fenetre, JPanel panneau) {
|
||||
super();
|
||||
this.fenetre = fenetre;
|
||||
this.panneau = panneau;
|
||||
}
|
||||
|
||||
public void windowActivated(WindowEvent evenement) {
|
||||
|
||||
} // premier plan
|
||||
|
||||
public void windowClosed(WindowEvent evenement) {
|
||||
|
||||
}
|
||||
public void windowClosing(WindowEvent evenement) {
|
||||
try {
|
||||
Dimension dims = this.fenetre.getSize();
|
||||
Point loc = this.fenetre.getLocation();
|
||||
Color color = this.panneau.getBackground();
|
||||
FileOutputStream fichier = new FileOutputStream("windowlocation.bin");
|
||||
DataOutputStream flux = new DataOutputStream(fichier);
|
||||
|
||||
try {
|
||||
flux.writeInt((int) loc.getX());
|
||||
flux.writeInt((int) loc.getY());
|
||||
flux.writeInt((int) dims.getWidth());
|
||||
flux.writeInt((int) dims.getHeight());
|
||||
flux.writeInt(color.getRed());
|
||||
flux.writeInt(color.getGreen());
|
||||
flux.writeInt(color.getBlue());
|
||||
} catch (IOException e2){
|
||||
System.out.println("Erreur d'écriture");
|
||||
}
|
||||
|
||||
try {
|
||||
flux.close();
|
||||
} catch (IOException e3) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
} // avant fermeture
|
||||
|
||||
public void windowDeactivated(WindowEvent evenement) {
|
||||
|
||||
} // arrière-plan
|
||||
|
||||
public void windowDeiconified(WindowEvent evenement) {
|
||||
|
||||
} // restauration
|
||||
|
||||
public void windowIconified(WindowEvent evenement){
|
||||
|
||||
} // minimisation
|
||||
|
||||
public void windowOpened(WindowEvent evenement) {
|
||||
try {
|
||||
FileInputStream fichier = new FileInputStream("windowlocation.bin");
|
||||
DataInputStream flux = new DataInputStream(fichier);
|
||||
|
||||
try {
|
||||
|
||||
if (flux.available() >= 28) {
|
||||
this.fenetre.setLocation(flux.readInt(), flux.readInt());
|
||||
this.fenetre.setSize(flux.readInt(), flux.readInt());
|
||||
this.panneau.setBackground(new Color(flux.readInt(), flux.readInt(), flux.readInt()));
|
||||
System.out.println(this.panneau.getBackground() + "");
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e5) {
|
||||
System.out.println("Erreur de lecture");
|
||||
}
|
||||
|
||||
try {
|
||||
flux.close();
|
||||
} catch (IOException e6) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
|
||||
} catch (IOException e4) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP12/01_Memoire/Fond$1.class
Normal file
BIN
DEV2.1/TP12/01_Memoire/Fond$1.class
Normal file
Binary file not shown.
BIN
DEV2.1/TP12/01_Memoire/Fond$2.class
Normal file
BIN
DEV2.1/TP12/01_Memoire/Fond$2.class
Normal file
Binary file not shown.
BIN
DEV2.1/TP12/01_Memoire/Fond$3.class
Normal file
BIN
DEV2.1/TP12/01_Memoire/Fond$3.class
Normal file
Binary file not shown.
BIN
DEV2.1/TP12/01_Memoire/Fond.class
Normal file
BIN
DEV2.1/TP12/01_Memoire/Fond.class
Normal file
Binary file not shown.
46
DEV2.1/TP12/01_Memoire/Fond.java
Normal file
46
DEV2.1/TP12/01_Memoire/Fond.java
Normal file
@@ -0,0 +1,46 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class Fond {
|
||||
public static void main(String[] args) {
|
||||
JFrame fenetre = new JFrame();
|
||||
JPanel panneau = new JPanel();
|
||||
FermetureFenetre evenementFenetre = new FermetureFenetre(fenetre, panneau);
|
||||
fenetre.addWindowListener(evenementFenetre);
|
||||
fenetre.setLocation(100,100);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.setLayout(new GridLayout(1, 1));
|
||||
|
||||
|
||||
JButton bouton1 = new JButton("Cyan");
|
||||
JButton bouton2 = new JButton("Magenta");
|
||||
JButton bouton3 = new JButton("Jaune");
|
||||
|
||||
bouton1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evenement) {
|
||||
panneau.setBackground(Color.CYAN);
|
||||
}
|
||||
});
|
||||
|
||||
bouton2.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evenement) {
|
||||
panneau.setBackground(Color.MAGENTA);
|
||||
}
|
||||
});
|
||||
|
||||
bouton3.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evenement) {
|
||||
panneau.setBackground(Color.YELLOW);
|
||||
}
|
||||
});
|
||||
|
||||
panneau.add(bouton1);
|
||||
panneau.add(bouton2);
|
||||
panneau.add(bouton3);
|
||||
|
||||
fenetre.add(panneau);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP12/01_Memoire/windowlocation.bin
Normal file
BIN
DEV2.1/TP12/01_Memoire/windowlocation.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user