From f922df24d7fea254736b634043ac1b30e5df57ab Mon Sep 17 00:00:00 2001 From: Simon Saye Babu Date: Tue, 9 May 2023 11:23:33 +0200 Subject: [PATCH] TP I/O --- DEV2.1/TP7/Coloriage.class | Bin 0 -> 610 bytes DEV2.1/TP7/Coloriage.java | 18 ++++++ DEV2.1/TP7/FluxImage.java | 101 ++++++++++++++++++++++++++++++++++ DEV2.1/TP7/Fond.java | 9 ++- DEV2.1/TP7/ImageColorer.class | Bin 0 -> 1097 bytes DEV2.1/TP7/ImageColorer.java | 38 +++++++++++++ DEV2.1/TP7/Main.java | 34 ++++++++++++ DEV2.1/TP7/MainFond.java | 72 ++++++++++++++++++------ DEV2.1/TP7/Polygone.java | 35 ++++++++++++ DEV2.1/TP7/Polygoneur.java | 20 +++++++ DEV2.1/TP7/image.java | 44 --------------- DEV2.1/TP7/polygone.bin | Bin 0 -> 320 bytes DEV2.1/TP7/save.bin | Bin 0 -> 28 bytes 13 files changed, 308 insertions(+), 63 deletions(-) create mode 100644 DEV2.1/TP7/Coloriage.class create mode 100644 DEV2.1/TP7/Coloriage.java create mode 100644 DEV2.1/TP7/FluxImage.java create mode 100644 DEV2.1/TP7/ImageColorer.class create mode 100644 DEV2.1/TP7/ImageColorer.java create mode 100644 DEV2.1/TP7/Main.java create mode 100644 DEV2.1/TP7/Polygone.java create mode 100644 DEV2.1/TP7/Polygoneur.java delete mode 100644 DEV2.1/TP7/image.java create mode 100644 DEV2.1/TP7/polygone.bin create mode 100644 DEV2.1/TP7/save.bin diff --git a/DEV2.1/TP7/Coloriage.class b/DEV2.1/TP7/Coloriage.class new file mode 100644 index 0000000000000000000000000000000000000000..8d54e5197be94c8f1c9ebda46284e455d97560a9 GIT binary patch literal 610 zcmZvZ-A>y;5QWdgPMkOVd+AA741;OXYIq` zg&d`X!W$K<^ew^in*#?$Ld}T2wI^4KWgiX_5lI&gEECEeJS-5LiA?+IyCmfOZnrrw zy+sd8rdQ@(Pme^ZbZqK156f5~G`Rj=ei73!?Sy(F4=-hMCnDHBdpKAnc-=^x$&LfdMg62@y`15}$KXYVN5_Gk;px5e7K-dqum&zc;XzX6-5dIbOg literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c53e7ee8f1b3a533a81d497408ad6d1c2b8b7f01 GIT binary patch literal 1097 zcmaJ=?M@Rx6g|^j*tSlg1&VyM2q@Ssm5L~S6cAel)_^2nO61?t4rR67*6kL20A9ks z{PDMm7Ndy|;3N15J^~@)odqn3iP`Mz+?HaMzczLBtT(FvM{U!xy|V zvn9u@?OKI8B~fsM=?aEuLT`z@h?BAqMmetI21&5$Yc=z2gTPd*Eg2f;xQPTqs3hF1 zS$I=&stvoy&~=&2s|7K|kmQ&^ikL{A=Vjrd4!zy-O*{ z5bkhH%TRzq%fc${x{~`I#|-Y%fgP({UKa%_lqMTQ9g^XP9FLHpLq*5j_gcg-ed%t` zl`)J~4J@zwo_}q-E}T8#Wb`drsDI0^=NZ&owMeDuT(NBNqEXov&P#KEOMWNj- xdZ(JWo01AW&x6gDssTzEGy`p-i686)qZ%O?o|5guvp=pB@QeTe literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..329c5a5439b7fa9f756602079796a31d85795871 GIT binary patch literal 320 zcmZvXp$&jQ5CpFhG%cVh0S%fG(3F4%O$lgPKvN8}8bkm9KqUi| literal 0 HcmV?d00001