diff --git a/DEV2.1/TP7/Coloriage.class b/DEV2.1/TP7/Coloriage.class
new file mode 100644
index 0000000..8d54e51
Binary files /dev/null and b/DEV2.1/TP7/Coloriage.class differ
diff --git a/DEV2.1/TP7/Coloriage.java b/DEV2.1/TP7/Coloriage.java
new file mode 100644
index 0000000..e95e138
--- /dev/null
+++ b/DEV2.1/TP7/Coloriage.java
@@ -0,0 +1,18 @@
+import java.awt.*;
+import java.lang.String;
+import javax.swing.*;
+import java.io.*;
+
+public class Coloriage {
+ public static void main(String[] args) {
+ JFrame fenetre = new JFrame();
+ fenetre.setSize(768,1024);
+ fenetre.setLocation(0,0);
+ fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ ImageColorer m = new ImageColorer(args[0]);
+ fenetre.add(m);
+
+ fenetre.setVisible(true);
+ }
+}
\ No newline at end of file
diff --git a/DEV2.1/TP7/FluxImage.java b/DEV2.1/TP7/FluxImage.java
new file mode 100644
index 0000000..3d6b62e
--- /dev/null
+++ b/DEV2.1/TP7/FluxImage.java
@@ -0,0 +1,101 @@
+import java.awt.image.*;
+import javax.swing.JComponent;
+import java.awt.Graphics;
+import java.awt.*;
+import java.io.*;
+
+/**
+ * TP Flux octets Exo 1. :
+ *
+ * @version 1
+ * @author Katia AUXILIEN
+ */
+public class FluxImage extends JComponent {
+ private BufferedImage img = new BufferedImage(768,1024,BufferedImage.TYPE_3BYTE_BGR);
+
+ /**
+ * ..
+ *
+ * @param args ..
+ */
+
+ public FluxImage() {
+ super();
+ int rgb,r,g,b;
+ try{
+ BufferedInputStream fis = new BufferedInputStream(new FileInputStream("image.bin"));
+ for(int y=0;y<1024;y++){
+ for (int x=0;x<768;x++) {
+ r=fis.read()<<16;
+ g=fis.read()<<8;
+ b=fis.read();
+ rgb = r | g | b;
+ //System.out.println(x+","+y+":"+x*y);
+ this.img.setRGB(x,y,rgb);
+ }
+ }
+ fis.close();
+ }
+ catch(IOException e){
+ System.out.println("Message d'erreur");
+ }
+
+ }
+
+
+ @Override
+ protected void paintComponent(Graphics pinceau) {
+ Graphics secondPinceau = pinceau.create();
+ if(this.isOpaque()){
+ secondPinceau.setColor(this.getBackground());
+ secondPinceau.fillRect(0,0,this.getWidth(),this.getHeight());
+ }
+ secondPinceau.drawImage(this.img,0,0,this);
+ }
+
+}
+
+/* PROF :
+private int width,height;
+ private String path;
+ private Image image;
+
+ public FluxImage(int width,int height, String path) throws IOException {
+ this.width=width;
+ this.height=height;
+ this.path = path;
+ this.image = readFromFile(width,height,path);
+ setPreferredSize(new Dimension(width,height));
+
+ this.repaint();
+
+ }
+
+ private Image readFromFile(int width, int height, String path) throws IOException {
+ FileInputStream input = new FileInputStream(path);
+ BufferedImage img = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
+
+ for(int i = 0; i < width ; i++){
+ for (int j = 0;j < width ;j++) {
+ int r = input.read();
+ int g = input.read();
+ int b = input.read();
+ //on pourrait ajouter une condition de vérification des valeurs rgb
+ int rgb = (r <<16)|(g << 8)|(b); //bit à bit on fait | pas || !!!
+ img.setRGB(j,i,rgb);
+ }
+ }
+ return img;
+ }
+
+ @Override
+ protected void paintComponent(Graphics pinceau) {
+ Graphics secondPinceau = pinceau.create();
+ if (this.isOpaque()) {
+ secondPinceau.setColor(this.getBackground());
+ secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
+ }
+ secondPinceau.drawImage(this.image, this.height,this.width, this);
+ }
+
+}*/
\ No newline at end of file
diff --git a/DEV2.1/TP7/Fond.java b/DEV2.1/TP7/Fond.java
index f88ee19..e50a741 100644
--- a/DEV2.1/TP7/Fond.java
+++ b/DEV2.1/TP7/Fond.java
@@ -1,11 +1,13 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
-import java.io.*;
public class Fond extends JPanel implements ActionListener {
- public Fond(){
+ int etat = 0;
+
+ public Fond()
+ {
super();
JButton bouton = new JButton("Blue");
this.add(bouton);
@@ -24,12 +26,15 @@ public class Fond extends JPanel implements ActionListener {
if (e.getActionCommand()=="Blue") {
this.setBackground(Color.BLUE);
+ this.etat = 1;
}
if (e.getActionCommand()=="Red") {
this.setBackground(Color.RED);
+ this.etat = 2;
}
if (e.getActionCommand()=="Green") {
this.setBackground(Color.GREEN);
+ this.etat = 3;
}
}
}
\ No newline at end of file
diff --git a/DEV2.1/TP7/ImageColorer.class b/DEV2.1/TP7/ImageColorer.class
new file mode 100644
index 0000000..c53e7ee
Binary files /dev/null and b/DEV2.1/TP7/ImageColorer.class differ
diff --git a/DEV2.1/TP7/ImageColorer.java b/DEV2.1/TP7/ImageColorer.java
new file mode 100644
index 0000000..8de8f68
--- /dev/null
+++ b/DEV2.1/TP7/ImageColorer.java
@@ -0,0 +1,38 @@
+import java.awt.image.*;
+import javax.swing.JComponent;
+import java.awt.Graphics;
+
+
+public class ImageColorer extends JComponent
+{
+ private BufferedImage img = new BufferedImage(768,1024,BufferedImage.TYPE_3BYTE_BGR);
+
+ public ImageColorer(String hex)
+ {
+ super();
+ int rgb = Integer.parseInt(hex,16);
+ for(int y=0;y<1024;y++)
+ {
+ for (int x=0;x<768;x++)
+ {
+ this.img.setRGB(x,y,rgb);
+ }
+ }
+
+ }
+
+
+ @Override
+ protected void paintComponent(Graphics pinceau)
+ {
+ Graphics secondPinceau = pinceau.create();
+ if(this.isOpaque())
+ {
+ secondPinceau.setColor(this.getBackground());
+ secondPinceau.fillRect(0,0,this.getWidth(),this.getHeight());
+ }
+ secondPinceau.drawImage(this.img,0,0,this);
+ }
+
+}
+
diff --git a/DEV2.1/TP7/Main.java b/DEV2.1/TP7/Main.java
new file mode 100644
index 0000000..e0dadfd
--- /dev/null
+++ b/DEV2.1/TP7/Main.java
@@ -0,0 +1,34 @@
+import java.awt.*;
+import java.lang.String;
+import javax.swing.*;
+import java.io.*;
+/*import java.lang.Object;
+import java.lang.StringBuffer;
+import java.lang.StringBuilder;
+*/
+
+/**
+ * Exercice 1 : a. :
+ *
+ * @version 1
+ * @author Katia AUXILIEN merciiiii
+ */
+public class Main {
+
+ /**
+ * Affiche message en argument
+ *
+ * @param args Message affiche.
+ */
+ public static void main(String[] args) {
+ JFrame fenetre = new JFrame();
+ fenetre.setSize(768,1024);
+ fenetre.setLocation(0,0);
+ fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ FluxImage m = new FluxImage();
+ fenetre.add(m);
+
+ fenetre.setVisible(true);
+ }
+}
\ No newline at end of file
diff --git a/DEV2.1/TP7/MainFond.java b/DEV2.1/TP7/MainFond.java
index 57d72d0..fbe6417 100644
--- a/DEV2.1/TP7/MainFond.java
+++ b/DEV2.1/TP7/MainFond.java
@@ -1,47 +1,85 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
+import java.io.*;
public class MainFond {
public static void main(String[] args) {
- int bg = 0
+ 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);
- bg = dis.readInt();
+ w = dis.readInt();
+ h = dis.readInt();
+ x = (int) dis.readDouble();
+ y = (int) dis.readDouble();
+ oldColor = dis.readInt();
+ dis.close();
}
catch(IOException e)
{
- if(e=SecurityException)
- {
System.out.println("probleme de lecture");
- }
}
JFrame fenetre = new JFrame();
- fenetre.setSize(1000, 1000);
- fenetre.setLocation(0, 0);
+ fenetre.setSize(w, h);
+ fenetre.setLocation(x, y);
Fond tamere = new Fond();
- if (bg==1)
+ switch(oldColor)
{
- tamere.setBackground(Color.BLUE);
- }
- if (bg==2)
- {
- tamere.setBackground(Color.RED);
- }
- if (bg==3)
- {
- tamere.setBackground(Color.GREEN);
+ 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);
}
}
\ No newline at end of file
diff --git a/DEV2.1/TP7/Polygone.java b/DEV2.1/TP7/Polygone.java
new file mode 100644
index 0000000..5d48189
--- /dev/null
+++ b/DEV2.1/TP7/Polygone.java
@@ -0,0 +1,35 @@
+import javax.swing.*;
+import java.awt.*;
+import java.io.*;
+
+public class Polygone extends JPanel
+{
+ public static void main(String[] args) {
+
+ try
+ {
+ int[] xPoints = new int[100]; // Coordonnées x des sommets du polygone
+ int[] yPoints = new int[100]; // Coordonnées y des sommets du polygone
+ FileInputStream fis = new FileInputStream("./polygone.bin");
+ DataInputStream dis = new DataInputStream(fis);
+ int i = 0;
+ while(dfgxfd!=-1);
+ {
+ xPoints[i] = dis.readInt();
+ }
+ dis.close();
+ }
+ catch(IOException e)
+ {
+ System.out.println("probleme de lecture");
+ }
+ JFrame frame = new JFrame();
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setSize(300, 300);
+
+ Polygoneur poly = new Polygoneur(xPoints,yPoints);
+ frame.add(poly);
+
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file
diff --git a/DEV2.1/TP7/Polygoneur.java b/DEV2.1/TP7/Polygoneur.java
new file mode 100644
index 0000000..c146ce3
--- /dev/null
+++ b/DEV2.1/TP7/Polygoneur.java
@@ -0,0 +1,20 @@
+import javax.swing.*;
+import java.awt.*;
+import java.io.*;
+
+public class Polygoneur extends JPanel
+{
+ @Override
+ protected void paintComponent(Graphics g)
+ {
+ super.paintComponent(g);
+
+ }
+
+ public Polygoneur(int[] xp,int[] yp)
+ {
+ g.setColor(Color.BLUE); // Couleur de remplissage
+ g.fillPolygon(xp, yp, xp.length);
+ }
+
+}
\ No newline at end of file
diff --git a/DEV2.1/TP7/image.java b/DEV2.1/TP7/image.java
deleted file mode 100644
index 0ffd3ee..0000000
--- a/DEV2.1/TP7/image.java
+++ /dev/null
@@ -1,44 +0,0 @@
-import java.io.*;
-import javax.swing.*;
-import java.awt.*;
-
-public class Image {
- public static void main(String[] args) {
- //ouverture du fichier
- try
- {
- FileInputStream fos = new FileInputStream("image.bin");
- }
- catch(IOException e)
- {
- System.out.println("Erreur Ouverture du fichier");
- }
- try
- {
- BufferedImage img = new BufferedImage(768,1024,BufferedImage.TYPE_3BYTE_BGR);
- for(int x = 0;x<768;x++)
- {
- for(int y = 0;y<1024;y++)
- {
- int r = input.read();
- int g = input.read();
- int b = input.read();
- int rgb = (r<<16)|(g<<8)|(b);
- img setRGB(x,y,rgb);
- }
- }
- }
- catch( IOException e)
- {
- System.out.println("Erreur Lecture du fichier");
- }
-
- Frame frame = new JFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JLabel image = new JLabel(new ImageIcon(img));
- frame.add(image);
- frame.pack();
- frame.setVisible(true);
-
- }
-}
\ No newline at end of file
diff --git a/DEV2.1/TP7/polygone.bin b/DEV2.1/TP7/polygone.bin
new file mode 100644
index 0000000..329c5a5
Binary files /dev/null and b/DEV2.1/TP7/polygone.bin differ
diff --git a/DEV2.1/TP7/save.bin b/DEV2.1/TP7/save.bin
new file mode 100644
index 0000000..9818fba
Binary files /dev/null and b/DEV2.1/TP7/save.bin differ