This commit is contained in:
Adrian POURCHOT 2023-05-09 11:26:45 +02:00
parent 93c00d1ed0
commit 392e9a21f8
9 changed files with 73 additions and 2 deletions

Binary file not shown.

View File

@ -0,0 +1,36 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Fond2 extends JPanel implements ActionListener{
public Fond2() {
super();
JButton magenta = new JButton("magenta");
JButton cyan = new JButton("cyan");
JButton jaune = new JButton("jaune");
this.add(magenta);
this.add(cyan);
this.add(jaune);
magenta.addActionListener(this);
cyan.addActionListener(this);
jaune.addActionListener(this);
}
public void actionPerformed(ActionEvent evenement){
String commande = new String();
commande="cyan";
if(true==commande.equals(evenement.getActionCommand())){
this.setBackground(Color.CYAN);
}
commande="magenta";
if(true==commande.equals(evenement.getActionCommand())){
this.setBackground(Color.MAGENTA);
}
commande="jaune";
if(true==commande.equals(evenement.getActionCommand())){
this.setBackground(Color.YELLOW);
}
}
}

Binary file not shown.

View File

@ -13,6 +13,7 @@ public class Imag extends JComponent{
private Image readFromFile(int width, int height, String path) throws IOException { private Image readFromFile(int width, int height, String path) throws IOException {
FileInputStream input = new FileInputStream(path); FileInputStream input = new FileInputStream(path);
BufferedInputStream input2 = new BufferedInputStream(input);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
for (int i = 0; i < height; i++){ for (int i = 0; i < height; i++){
for (int j = 0; j < width; j++){ for (int j = 0; j < width; j++){
@ -36,6 +37,6 @@ public class Imag extends JComponent{
pinceau2.setColor(this.getBackground()); pinceau2.setColor(this.getBackground());
pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight()); pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight());
} }
pinceau2.drawImage(this.image, 768, 1024, this); pinceau2.drawImage(this.image, 0, 0, this);
} }
} }

View File

@ -7,6 +7,7 @@ public class MainImage{
public static void main(String[] args) { public static void main(String[] args) {
try{ try{
FileInputStream file = new FileInputStream("image.bin"); FileInputStream file = new FileInputStream("image.bin");
BufferedInputStream file2 = new BufferedInputStream(file);
try { try {
JFrame fenetre = new JFrame(); JFrame fenetre = new JFrame();
fenetre.setSize(1024, 768); fenetre.setSize(1024, 768);
@ -15,7 +16,7 @@ public class MainImage{
fenetre.add(new Imag(1024, 768, "image.bin")); fenetre.add(new Imag(1024, 768, "image.bin"));
fenetre.setVisible(true); fenetre.setVisible(true);
fenetre.pack(); fenetre.pack();
file.close(); file2.close();
} catch(IOException e){} } catch(IOException e){}
}catch(FileNotFoundException e){} }catch(FileNotFoundException e){}
} }

Binary file not shown.

View File

@ -0,0 +1,33 @@
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class Mainfond2{
public static void main(String[] args) {
try{
DataInputStream file = new DataInputStream(new FileInputStream ("taille.bin"));
BufferedInputStream file2 = new BufferedInputStream(file);
try {
JFrame fenetre = new JFrame();
Fond2 pan = new Fond2();
int x = file.readInt();
int y = file.readInt();
fenetre.setSize(x, y);
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setContentPane(pan);
fenetre.setVisible(true);
file2.close();
} catch(IOException e){}
}catch(FileNotFoundException e){
JFrame fenetre = new JFrame();
Fond2 pan = new Fond2();
fenetre.setSize(500, 500);
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setContentPane(pan);
fenetre.setVisible(true);
}
}
}

View File