TP
This commit is contained in:
1
DEV2.1/SAE21_2025
Submodule
1
DEV2.1/SAE21_2025
Submodule
Submodule DEV2.1/SAE21_2025 added at c5462401ed
BIN
DEV2.1/Sudoku/Case.class
Normal file
BIN
DEV2.1/Sudoku/Case.class
Normal file
Binary file not shown.
26
DEV2.1/Sudoku/Case.java
Normal file
26
DEV2.1/Sudoku/Case.java
Normal file
@@ -0,0 +1,26 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Case extends JComponent {
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
|
||||
if (this.isOpaque()) {
|
||||
secondPinceau.setColor(this.getBackground());
|
||||
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
secondPinceau.setColor(Color.BLACK);
|
||||
secondPinceau.drawRect(0, 0, this.getWidth()-3, this.getHeight()-3);
|
||||
secondPinceau.drawRect(1, 1, this.getWidth()-4, this.getHeight()-4);
|
||||
secondPinceau.drawRect(2, 2, this.getWidth()-5, this.getHeight()-5);
|
||||
|
||||
for (int i = 0; i != 3; i++) {
|
||||
for (int j = 0; j != 3; j++) {
|
||||
secondPinceau.drawRect(this.getWidth()*i/3, this.getHeight()*j/3, this.getWidth()/3, this.getHeight()/3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/Sudoku/Graphique.class
Normal file
BIN
DEV2.1/Sudoku/Graphique.class
Normal file
Binary file not shown.
17
DEV2.1/Sudoku/Graphique.java
Normal file
17
DEV2.1/Sudoku/Graphique.java
Normal file
@@ -0,0 +1,17 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Graphique extends JFrame {
|
||||
|
||||
public Graphique() {
|
||||
this.setSize(600, 600);
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
this.setLayout(new GridLayout(9, 9));
|
||||
|
||||
for (int i = 0; i != 81; i++) {
|
||||
this.add(new JTextField());
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/Sudoku/Main.class
Normal file
BIN
DEV2.1/Sudoku/Main.class
Normal file
Binary file not shown.
6
DEV2.1/Sudoku/Main.java
Normal file
6
DEV2.1/Sudoku/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Graphique fenetre = new Graphique();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TDs/Fenetre.class
Normal file
BIN
DEV2.1/TDs/Fenetre.class
Normal file
Binary file not shown.
0
DEV2.1/TDs/Fenetre.java
Normal file
0
DEV2.1/TDs/Fenetre.java
Normal file
BIN
DEV2.1/TDs/Img.class
Normal file
BIN
DEV2.1/TDs/Img.class
Normal file
Binary file not shown.
43
DEV2.1/TDs/Img.java
Normal file
43
DEV2.1/TDs/Img.java
Normal file
@@ -0,0 +1,43 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Img extends JComponent {
|
||||
private Image img;
|
||||
|
||||
public Img() {
|
||||
// Chargement de l'image
|
||||
img = new ImageIcon("fond.png").getImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (img != null) {
|
||||
g.drawImage(img, 0, 0, this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(500, 500); // Ajustez à la taille de l'image
|
||||
}
|
||||
}
|
||||
|
||||
class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Img imagePanel = new Img();
|
||||
this.add(imagePanel);
|
||||
|
||||
this.pack(); // Ajuste la fenêtre à la taille du contenu
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(Fenetre::new);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TDs/Main.class
Normal file
BIN
DEV2.1/TDs/Main.class
Normal file
Binary file not shown.
39
DEV2.1/TDs/Main.java
Normal file
39
DEV2.1/TDs/Main.java
Normal file
@@ -0,0 +1,39 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
class Img extends JComponent {
|
||||
private Image img;
|
||||
|
||||
public Img() {
|
||||
// Chargement de l'image
|
||||
img = Toolkit.getDefaultToolkit().getImage("triangles-1430105_1280.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (img != null) {
|
||||
g.drawImage(img, 0, 0, this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Img imagePanel = new Img();
|
||||
this.add(imagePanel);
|
||||
|
||||
this.pack(); // Ajuste la fenêtre à la taille du contenu
|
||||
}
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TDs/Reels.class
Normal file
BIN
DEV2.1/TDs/Reels.class
Normal file
Binary file not shown.
35
DEV2.1/TDs/Reels.java
Normal file
35
DEV2.1/TDs/Reels.java
Normal file
@@ -0,0 +1,35 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Reels {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
FileWriter fichier = new FileWriter("reels.txt");
|
||||
BufferedWriter flux = new BufferedWriter(fichier);
|
||||
|
||||
try {
|
||||
flux.write("12.8391319");
|
||||
flux.newLine();
|
||||
flux.write("45.72");
|
||||
flux.newLine();
|
||||
flux.write("12.283939273718317174");
|
||||
flux.newLine();
|
||||
flux.write("1.0");
|
||||
flux.newLine();
|
||||
|
||||
} catch (IOException e2 ) {
|
||||
System.out.println("Erreur d'écriture");
|
||||
}
|
||||
|
||||
try {
|
||||
flux.close();
|
||||
} catch (IOException e3) {
|
||||
|
||||
System.out.println("Erreur de femreture");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
BIN
DEV2.1/TDs/Somme.class
Normal file
BIN
DEV2.1/TDs/Somme.class
Normal file
Binary file not shown.
9
DEV2.1/TDs/Somme.java
Normal file
9
DEV2.1/TDs/Somme.java
Normal file
@@ -0,0 +1,9 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Somme {
|
||||
public static void main(String[] args) {
|
||||
InputStreamReader lecture = new InputStreamReader(System.in);
|
||||
BufferedReader flux = new BufferedReader(lecture);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TDs/fond.png
Normal file
BIN
DEV2.1/TDs/fond.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 476 KiB |
Binary file not shown.
4
DEV2.1/TDs/reels.txt
Normal file
4
DEV2.1/TDs/reels.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
12.8391319
|
||||
45.72
|
||||
12.283939273718317174
|
||||
1.0
|
BIN
DEV2.1/TDs/triangles-1430105_1280.png
Normal file
BIN
DEV2.1/TDs/triangles-1430105_1280.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 648 KiB |
BIN
DEV2.1/TDs/triangles-1430105_1280.webp
Normal file
BIN
DEV2.1/TDs/triangles-1430105_1280.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 476 KiB |
@@ -36,9 +36,9 @@ public class Nuance extends JPanel {
|
||||
for (String element : args) {
|
||||
element = element.replaceAll("#", "");
|
||||
int[] couleurs = {
|
||||
Integer.parseInt(element.substring(0,2), 16),
|
||||
Integer.parseInt(element.substring(2,4), 16),
|
||||
Integer.parseInt(element.substring(4,6), 16)
|
||||
Integer.parseInt(element.substring(5,7), 16),
|
||||
Integer.parseInt(element.substring(7,9), 16),
|
||||
Integer.parseInt(element.substring(9,11), 16)
|
||||
};
|
||||
fenetre.add(new Nuance(couleurs));
|
||||
}
|
||||
|
Binary file not shown.
@@ -1,9 +1,13 @@
|
||||
public class Conversion {
|
||||
public static double celsiusAFahrenheit(double n) {
|
||||
/** Prend en argument une température en degrés Celsius et
|
||||
* renvoie sa valeur en degrés Fahrenheit **/
|
||||
return n*9/5+32;
|
||||
}
|
||||
|
||||
public static double FahrenheitACelsius(double n) {
|
||||
/** Prend en argument une température en degrés Fahrenheit et
|
||||
* renvoie sa valeur en degrés Celsius **/
|
||||
return (n-32)*5/9;
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,7 +16,7 @@ public class LectureFichier {
|
||||
Color couleur;
|
||||
|
||||
try {
|
||||
FileInputStream fichier = new FileInputStream("image.bin");
|
||||
FileInputStream fichier = new FileInputStream("couleur.bin");
|
||||
|
||||
while(fichier.available() >= 3) {
|
||||
try {
|
||||
|
Binary file not shown.
Binary file not shown.
@@ -3,22 +3,22 @@ import java.io.*;
|
||||
|
||||
public class EcritureFichier {
|
||||
|
||||
private byte r;
|
||||
private byte g;
|
||||
private byte b;
|
||||
private int r;
|
||||
private int g;
|
||||
private int b;
|
||||
|
||||
private byte r2;
|
||||
private byte g2;
|
||||
private byte b2;
|
||||
private int r2;
|
||||
private int g2;
|
||||
private int b2;
|
||||
|
||||
public EcritureFichier(byte r, byte g, byte b) {
|
||||
public EcritureFichier(int r, int g, int b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
|
||||
try {
|
||||
FileOutputStream fichier = new FileOutputStream("couleur.bin");
|
||||
|
||||
System.out.println(r + " " + g + " " + b);
|
||||
try {
|
||||
for (int i = 0; i != 768; i++) {
|
||||
for (int j = 0; j != 1024; j++) {
|
||||
@@ -42,7 +42,7 @@ public class EcritureFichier {
|
||||
}
|
||||
}
|
||||
|
||||
public EcritureFichier(byte r, byte g, byte b, byte r2, byte g2, byte b2) {
|
||||
public EcritureFichier(int r, int g, int b, int r2, int g2, int b2) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
@@ -52,15 +52,42 @@ public class EcritureFichier {
|
||||
|
||||
try {
|
||||
FileOutputStream fichier = new FileOutputStream("couleur.bin");
|
||||
int choixR = r;
|
||||
int choixG = g;
|
||||
int choixB = b;
|
||||
|
||||
try {
|
||||
for (int i = 0; i != 768; i++) {
|
||||
for (int j = 0; j != 1024; j++) {
|
||||
fichier.write(r);
|
||||
fichier.write(g);
|
||||
fichier.write(b);
|
||||
for (int l = 0; l != 8; l++) {
|
||||
for (int k = 0; k != 8; k++) {
|
||||
for (int i = 0; i != 768/8; i++) {
|
||||
for (int j = 0; j != 1024/8; j++) {
|
||||
fichier.write(choixR);
|
||||
fichier.write(choixG);
|
||||
fichier.write(choixB);
|
||||
}
|
||||
if (choixR == r) {
|
||||
choixR = r2;
|
||||
choixG = g2;
|
||||
choixB = b2;
|
||||
}
|
||||
else {
|
||||
choixR = r;
|
||||
choixG = g;
|
||||
choixB = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (choixR == r) {
|
||||
choixR = r2;
|
||||
choixG = g2;
|
||||
choixB = b2;
|
||||
}
|
||||
else {
|
||||
choixR = r;
|
||||
choixG = g;
|
||||
choixB = b;
|
||||
}
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.out.println("Erreur d'écriture");
|
||||
}
|
||||
|
Binary file not shown.
@@ -1,11 +1,21 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
String chaineCouleur = args[0].replaceAll("#", "");
|
||||
Integer r = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(0, 2), 16));
|
||||
Integer g = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(2, 4), 16));
|
||||
Integer b = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(4, 6), 16));
|
||||
|
||||
if (args.length == 1) {
|
||||
String chaineCouleur = args[0].replaceAll("#", "");
|
||||
Integer r = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(0, 2), 16));
|
||||
Integer g = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(2, 4), 16));
|
||||
Integer b = Integer.valueOf(Integer.parseInt(chaineCouleur.substring(4, 6), 16));
|
||||
EcritureFichier ecriture = new EcritureFichier(r.byteValue(), g.byteValue(), b.byteValue());
|
||||
EcritureFichier ecriture = new EcritureFichier(r, g, b);
|
||||
}
|
||||
|
||||
else if (args.length == 2) {
|
||||
String chaineCouleur2 = args[1].replaceAll("#", "");
|
||||
Integer r2 = Integer.valueOf(Integer.parseInt(chaineCouleur2.substring(0, 2), 16));
|
||||
Integer g2 = Integer.valueOf(Integer.parseInt(chaineCouleur2.substring(2, 4), 16));
|
||||
Integer b2 = Integer.valueOf(Integer.parseInt(chaineCouleur2.substring(4, 6), 16));
|
||||
System.out.println(r + "," + g + "," + b + " | " + r2 + "," + g2 + "," + b2);
|
||||
EcritureFichier ecriture2 = new EcritureFichier(r, g, b, r2, g2, b2);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
108
DEV2.1/TP11/04_Palette/EcritureFichier.java
Normal file
108
DEV2.1/TP11/04_Palette/EcritureFichier.java
Normal file
@@ -0,0 +1,108 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
public class EcritureFichier {
|
||||
|
||||
private int r;
|
||||
private int g;
|
||||
private int b;
|
||||
|
||||
private int r2;
|
||||
private int g2;
|
||||
private int b2;
|
||||
|
||||
public EcritureFichier(int r, int g, int b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
|
||||
try {
|
||||
FileOutputStream fichier = new FileOutputStream("couleur.bin");
|
||||
System.out.println(r + " " + g + " " + b);
|
||||
try {
|
||||
for (int i = 0; i != 768; i++) {
|
||||
for (int j = 0; j != 1024; j++) {
|
||||
fichier.write(r);
|
||||
fichier.write(g);
|
||||
fichier.write(b);
|
||||
}
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.out.println("Erreur d'écriture");
|
||||
}
|
||||
|
||||
try {
|
||||
fichier.close();
|
||||
} catch (IOException e3) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
}
|
||||
|
||||
public EcritureFichier(int r, int g, int b, int r2, int g2, int b2) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.r2 = r2;
|
||||
this.g2 = g2;
|
||||
this.b2 = b2;
|
||||
|
||||
try {
|
||||
FileOutputStream fichier = new FileOutputStream("couleur.bin");
|
||||
int choixR = r;
|
||||
int choixG = g;
|
||||
int choixB = b;
|
||||
|
||||
try {
|
||||
for (int l = 0; l != 8; l++) {
|
||||
for (int k = 0; k != 8; k++) {
|
||||
for (int i = 0; i != 768/8; i++) {
|
||||
for (int j = 0; j != 1024/8; j++) {
|
||||
fichier.write(choixR);
|
||||
fichier.write(choixG);
|
||||
fichier.write(choixB);
|
||||
}
|
||||
if (choixR == r) {
|
||||
choixR = r2;
|
||||
choixG = g2;
|
||||
choixB = b2;
|
||||
}
|
||||
else {
|
||||
choixR = r;
|
||||
choixG = g;
|
||||
choixB = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (choixR == r) {
|
||||
choixR = r2;
|
||||
choixG = g2;
|
||||
choixB = b2;
|
||||
}
|
||||
else {
|
||||
choixR = r;
|
||||
choixG = g;
|
||||
choixB = b;
|
||||
}
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.out.println("Erreur d'écriture");
|
||||
}
|
||||
|
||||
try {
|
||||
fichier.close();
|
||||
} catch (IOException e3) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
12
DEV2.1/TP11/04_Palette/Fenetre.java
Normal file
12
DEV2.1/TP11/04_Palette/Fenetre.java
Normal file
@@ -0,0 +1,12 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setSize(768, 1024);
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(1, 1));
|
||||
this.add(new Image());
|
||||
}
|
||||
}
|
19
DEV2.1/TP11/04_Palette/Image.java
Normal file
19
DEV2.1/TP11/04_Palette/Image.java
Normal file
@@ -0,0 +1,19 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Image extends JComponent {
|
||||
@Override
|
||||
public void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
Color couleur;
|
||||
|
||||
if (this.isOpaque()) {
|
||||
secondPinceau.setColor(this.getBackground());
|
||||
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
secondPinceau.drawImage(new LectureFichier().getImage(), 0, 0, this);
|
||||
|
||||
}
|
||||
}
|
52
DEV2.1/TP11/04_Palette/LectureFichier.java
Normal file
52
DEV2.1/TP11/04_Palette/LectureFichier.java
Normal file
@@ -0,0 +1,52 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class LectureFichier {
|
||||
|
||||
private BufferedImage image;
|
||||
|
||||
public LectureFichier() {
|
||||
this.image = new BufferedImage(768, 1024, BufferedImage.TYPE_3BYTE_BGR);
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
Color couleur;
|
||||
|
||||
try {
|
||||
FileInputStream fichier = new FileInputStream("couleur.bin");
|
||||
|
||||
while(fichier.available() >= 3) {
|
||||
try {
|
||||
r = fichier.read();
|
||||
g = fichier.read();
|
||||
b = fichier.read();
|
||||
couleur = new Color(r, g, b);
|
||||
this.image.setRGB(i, j, couleur.getRGB());
|
||||
i++;
|
||||
if (i >= 768) {
|
||||
j++;
|
||||
i = 0;
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.out.println("Erreur d'accès");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
fichier.close();
|
||||
} catch (IOException e3) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
return this.image;
|
||||
}
|
||||
|
||||
}
|
6
DEV2.1/TP11/04_Palette/Main.java
Normal file
6
DEV2.1/TP11/04_Palette/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP11/04_Palette/couleur.bin
Normal file
BIN
DEV2.1/TP11/04_Palette/couleur.bin
Normal file
Binary file not shown.
BIN
DEV2.1/TP11/04_Palette/image.bin
Normal file
BIN
DEV2.1/TP11/04_Palette/image.bin
Normal file
Binary file not shown.
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);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user