Ajout des travaux effectuer
This commit is contained in:
71
23DEV1.1/TPS2/TP01/FluxDOctet/Image/TestImage.java
Normal file
71
23DEV1.1/TPS2/TP01/FluxDOctet/Image/TestImage.java
Normal file
@@ -0,0 +1,71 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestImage extends JPanel
|
||||
{
|
||||
private static final int WIDTH = 768;
|
||||
private static final int HEIGHT = 1024;
|
||||
private static final String FILE_PATH = "image.bin";
|
||||
|
||||
private BufferedImage image;
|
||||
|
||||
public TestImage()
|
||||
{
|
||||
try
|
||||
{
|
||||
loadImage();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void loadImage() throws IOException
|
||||
{
|
||||
FileInputStream fileInputStream = new FileInputStream(FILE_PATH);
|
||||
DataInputStream dataInputStream = new DataInputStream(fileInputStream);
|
||||
byte[] imageData = new byte[WIDTH * HEIGHT * 3];
|
||||
// Lecture des données de l'image
|
||||
dataInputStream.readFully(imageData);
|
||||
dataInputStream.close();
|
||||
// Création d'une BufferedImage
|
||||
image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
|
||||
// Remplissage de l'image à partir des données lues
|
||||
int index = 0; for (int y = 0; y < HEIGHT; y++)
|
||||
{
|
||||
for (int x = 0; x < WIDTH; x++)
|
||||
{
|
||||
int r = imageData[index++] & 0xFF;
|
||||
// Rouge
|
||||
int g = imageData[index++] & 0xFF;
|
||||
// Vert
|
||||
int b = imageData[index++] & 0xFF;
|
||||
// Bleu
|
||||
int rgb = (r << 16) | (g << 8) | b;
|
||||
image.setRGB(x, y, rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics g)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
g.drawImage(image, 0, 0, null);
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JFrame frame = new JFrame("Image Display");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.getContentPane().add(new ImageDisplay());
|
||||
frame.pack();
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
23DEV1.1/TPS2/TP01/FluxDOctet/Image/image.bin
Normal file
BIN
23DEV1.1/TPS2/TP01/FluxDOctet/Image/image.bin
Normal file
Binary file not shown.
BIN
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/Fond.class
Normal file
BIN
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/Fond.class
Normal file
Binary file not shown.
30
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/Fond.java
Normal file
30
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/Fond.java
Normal file
@@ -0,0 +1,30 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Fond extends JPanel implements ActionListener
|
||||
{
|
||||
public Fond(){
|
||||
super();
|
||||
JButton cyan = new JButton("Cyan");
|
||||
JButton magenta = new JButton("Magenta");
|
||||
JButton jaune = new JButton("Jaune");
|
||||
this.add(cyan);
|
||||
this.add(magenta);
|
||||
this.add(jaune);
|
||||
cyan.addActionListener(this);
|
||||
magenta.addActionListener(this);
|
||||
jaune.addActionListener(this);
|
||||
}
|
||||
public void actionPerformed(ActionEvent evenement){
|
||||
String test;
|
||||
test = evenement.getActionCommand();
|
||||
if(test.equals("Cyan")){
|
||||
this.setBackground(Color.CYAN);
|
||||
}if(test.equals("Magenta")){
|
||||
this.setBackground(Color.MAGENTA);
|
||||
}if(test.equals("Jaune")){
|
||||
this.setBackground(Color.YELLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/Test.class
Normal file
BIN
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/Test.class
Normal file
Binary file not shown.
21
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/Test.java
Normal file
21
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/Test.java
Normal file
@@ -0,0 +1,21 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Test{
|
||||
|
||||
public static void main(String[] args){
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.add(new Fond());
|
||||
fenetre.setVisible(true);
|
||||
try{
|
||||
FileInputStream file = new FileInputStream("/tmp/memoire/save.bin");
|
||||
BufferedInputStream buff = new BufferedInputStream(file);
|
||||
}catch(IOException e){
|
||||
fenetre.setSize(300, 300);
|
||||
fenetre.setLocation(100, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/memoire.java
Normal file
36
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/memoire.java
Normal file
@@ -0,0 +1,36 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
public class memoire{
|
||||
public void windowOpened(WindowEvent event){
|
||||
Window window = event.getWindow();
|
||||
Point defaultLocation = new Point(0, 0);
|
||||
Dimension defaultDimension = Dimension(400, 400);
|
||||
try(ObjectInputStream input = new ObjectInputStream(new FileInputStream("/tmp/memoire/save.bin"))){
|
||||
Object location = input.readObject();
|
||||
Object size = input.readObject();
|
||||
if(size instanceof Point){
|
||||
defaultLocation = (Point)location;
|
||||
}
|
||||
if(size instanceof Dimension){
|
||||
defaultDimension = (Dimension)size;
|
||||
}
|
||||
}catch(IOException | ClassNotFoundException e){
|
||||
}
|
||||
window.setLocation(defaultLocation);
|
||||
window.setSize(defaultDimension);
|
||||
}
|
||||
public void windowClosing(WindowEvent event){
|
||||
Window window = event.getWindow();
|
||||
try(ObjectOutputStream input = new ObjectOutputStream(new FileOutputStream("/tmp/memoire/save.bin"))){
|
||||
input.writeObject(window.getLocation());
|
||||
input.writeObject(window.getSize());
|
||||
}catch(IOException | ClassNotFoundException e){
|
||||
System.out.println(e.getMessage);
|
||||
}
|
||||
}
|
||||
public memoire(){
|
||||
super();
|
||||
}
|
||||
}
|
||||
36
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/memory.java
Normal file
36
23DEV1.1/TPS2/TP01/FluxDOctet/Mémoire/memory.java
Normal file
@@ -0,0 +1,36 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
public class memoire extends implement{
|
||||
public void windowOpened(WindowEvent event){
|
||||
Window window = event.getWindow();
|
||||
Point defaultLocation = new Point(0, 0);
|
||||
Dimension defaultDimension = Dimension(400, 400);
|
||||
try(ObjectInputStream input = new ObjectInputStream(new FileInputStream("/tmp/memoire/save.bin"))){
|
||||
Object location = input.readObject();
|
||||
Object size = input.readObject();
|
||||
if(size instanceof Point){
|
||||
defaultLocation = (Point)location;
|
||||
}
|
||||
if(size instanceof Dimension){
|
||||
defaultDimension = (Dimension)size;
|
||||
}
|
||||
}catch(IOException | ClassNotFoundException e){
|
||||
}
|
||||
window.setLocation(defaultLocation);
|
||||
window.setSize(defaultDimension);
|
||||
}
|
||||
public void windowClosing(WindowEvent event){
|
||||
Window window = event.getWindow();
|
||||
try(ObjectOutputStream input = new ObjectOutputStream(new FileOutputStream("/tmp/memoire/save.bin"))){
|
||||
input.writeObject(window.getLocation());
|
||||
input.writeObject(window.getSize());
|
||||
}catch(IOException | ClassNotFoundException e){
|
||||
System.out.println(e.getMessage);
|
||||
}
|
||||
}
|
||||
public memoire(){
|
||||
super();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user