oups betise :x
This commit is contained in:
Simon SAYE BABU 2023-09-20 12:15:14 +02:00
commit 0d553d9bfd
13 changed files with 308 additions and 63 deletions

BIN
DEV2.1/TP7/Coloriage.class Normal file

Binary file not shown.

18
DEV2.1/TP7/Coloriage.java Normal file
View File

@ -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);
}
}

101
DEV2.1/TP7/FluxImage.java Normal file
View File

@ -0,0 +1,101 @@
import java.awt.image.*;
import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.*;
import java.io.*;
/**
* <b>TP Flux octets Exo 1. </b> :
*
* @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);
}
}*/

View File

@ -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;
}
}
}

Binary file not shown.

View File

@ -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);
}
}

34
DEV2.1/TP7/Main.java Normal file
View File

@ -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;
*/
/**
* <b>Exercice 1 : a. </b> :
*
* @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);
}
}

View File

@ -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);
}
}

35
DEV2.1/TP7/Polygone.java Normal file
View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

BIN
DEV2.1/TP7/polygone.bin Normal file

Binary file not shown.

BIN
DEV2.1/TP7/save.bin Normal file

Binary file not shown.