diff --git a/APL2.1/TP13/Coloriage/Coloriage.class b/APL2.1/TP13/Coloriage/Coloriage.class new file mode 100644 index 0000000..960ae70 Binary files /dev/null and b/APL2.1/TP13/Coloriage/Coloriage.class differ diff --git a/APL2.1/TP13/Coloriage/Coloriage.java b/APL2.1/TP13/Coloriage/Coloriage.java new file mode 100644 index 0000000..6e3c977 --- /dev/null +++ b/APL2.1/TP13/Coloriage/Coloriage.java @@ -0,0 +1,33 @@ +import java.awt.Color; +import java.io.FileOutputStream; +import java.io.IOException; + +public class Coloriage { + + private static final int x = 500; + private static final int y = 500; + public static void main(String[] args) { + Color c1 = Color.decode(args[0]); + Color c2 = Color.decode(args[1]); + + try (FileOutputStream f = new FileOutputStream("funny.bin")) { + try { + for (int i = 0; i < x*y; i++) { + f.write((byte)c1.getRed()); + f.write((byte)c1.getGreen()); + f.write((byte)c1.getBlue()); + } + } catch (IOException e) { + System.out.println(e); + } + + try { + f.close(); + } catch (IOException e) { + System.out.println(e); + } + } catch (IOException e) { + System.out.println(e); + } + } +} diff --git a/APL2.1/TP13/Image/ImagePanel.class b/APL2.1/TP13/Image/ImagePanel.class new file mode 100644 index 0000000..00505f0 Binary files /dev/null and b/APL2.1/TP13/Image/ImagePanel.class differ diff --git a/APL2.1/TP13/Image/ImagePanel.java b/APL2.1/TP13/Image/ImagePanel.java new file mode 100644 index 0000000..cae806e --- /dev/null +++ b/APL2.1/TP13/Image/ImagePanel.java @@ -0,0 +1,23 @@ +import javax.swing.JPanel; +import java.awt.Graphics; +import java.awt.Image; + +public class ImagePanel extends JPanel { + private Image img; + + public ImagePanel(Image img) { + super(); + this.img = img; + } + + @Override + protected void paintComponent(Graphics g) { + Graphics newG = g.create(); + if (this.isOpaque()) { + newG.setColor(this.getBackground()); + newG.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + + newG.drawImage(img, 0, 0, img.getWidth(this), img.getHeight(this), this); + } +} \ No newline at end of file diff --git a/APL2.1/TP13/Image/ImageTest.class b/APL2.1/TP13/Image/ImageTest.class new file mode 100644 index 0000000..e2c8826 Binary files /dev/null and b/APL2.1/TP13/Image/ImageTest.class differ diff --git a/APL2.1/TP13/Image/ImageTest.java b/APL2.1/TP13/Image/ImageTest.java new file mode 100644 index 0000000..35af81a --- /dev/null +++ b/APL2.1/TP13/Image/ImageTest.java @@ -0,0 +1,48 @@ +import javax.swing.*; +import java.awt.image.BufferedImage; +import java.io.FileInputStream; +import java.io.IOException; + +public class ImageTest { + static int width = 100; + static int height = 100; + + public static void main(String[] args) { + BufferedImage img = new BufferedImage(ImageTest.width, ImageTest.height, BufferedImage.TYPE_3BYTE_BGR); + + try (FileInputStream f = new FileInputStream("../Coloriage/funny.bin")) { + + for (int i = 0; i < width * height; i++) { + int r = f.read(); + int g = f.read(); + int b = f.read(); + + int rgb = r; + rgb <<= 8; + rgb |= g; + rgb <<= 8; + rgb |= b; + + img.setRGB(i % width, i / width, rgb); + } + + + + try { + f.close(); + } catch (IOException e) { + System.out.println(e); + } + } catch (IOException e) { + System.out.println(e); + } + + + JFrame f = new JFrame("Image"); + f.setSize(width + 50, height + 50); + f.setLocation(100, 100); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.add(new ImagePanel(img)); + f.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP13/Image/funny.bin b/APL2.1/TP13/Image/funny.bin new file mode 100644 index 0000000..a102f09 Binary files /dev/null and b/APL2.1/TP13/Image/funny.bin differ diff --git a/APL2.1/TP13/Image/image.bin b/APL2.1/TP13/Image/image.bin new file mode 100644 index 0000000..1bf996b Binary files /dev/null and b/APL2.1/TP13/Image/image.bin differ diff --git a/APL2.1/TP13/Memoire/CloseListener.class b/APL2.1/TP13/Memoire/CloseListener.class new file mode 100644 index 0000000..8d64a55 Binary files /dev/null and b/APL2.1/TP13/Memoire/CloseListener.class differ diff --git a/APL2.1/TP13/Memoire/CloseListener.java b/APL2.1/TP13/Memoire/CloseListener.java new file mode 100644 index 0000000..e401622 --- /dev/null +++ b/APL2.1/TP13/Memoire/CloseListener.java @@ -0,0 +1,75 @@ +import java.awt.Point; +import java.awt.event.*; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; + +import javax.swing.JFrame; + +public class CloseListener implements WindowListener { + + @Override + public void windowActivated(WindowEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void windowClosed(WindowEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void windowClosing(WindowEvent arg0) { + JFrame window = (JFrame)arg0.getSource(); + + try (ObjectOutputStream f = new ObjectOutputStream(new FileOutputStream("save.dat"))) { + int width = window.getWidth(); + int height = window.getHeight(); + Point location = window.getLocation(); + + try { + f.writeInt(width); + f.writeInt(height); + f.writeInt((int)location.getX()); + f.writeInt((int)location.getY()); + } catch (IOException e) { + System.out.println(e); + } + + try { + f.close(); + } catch (IOException e) { + System.out.println(e); + } + } catch (IOException e) { + System.out.println(e); + } + } + + @Override + public void windowDeactivated(WindowEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void windowDeiconified(WindowEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void windowIconified(WindowEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void windowOpened(WindowEvent arg0) { + // TODO Auto-generated method stub + + } + +} diff --git a/APL2.1/TP13/Memoire/Fond.class b/APL2.1/TP13/Memoire/Fond.class new file mode 100644 index 0000000..c570310 Binary files /dev/null and b/APL2.1/TP13/Memoire/Fond.class differ diff --git a/APL2.1/TP13/Memoire/Fond.java b/APL2.1/TP13/Memoire/Fond.java new file mode 100644 index 0000000..537b8d1 --- /dev/null +++ b/APL2.1/TP13/Memoire/Fond.java @@ -0,0 +1,58 @@ +import java.awt.*; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; + +import javax.swing.*; + +public class Fond { + public static void main(String[] args) { + JFrame f = new JFrame("Fond"); + f.setSize(200, 200); + f.setLocation(100, 100); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setLayout(new GridLayout(1, 3)); + + JButton b1 = new JButton("Jaune"); + JButton b2 = new JButton("Cyan"); + JButton b3 = new JButton("Magenta"); + + Observer observer = new Observer(); + + b1.addActionListener(observer); + b2.addActionListener(observer); + b3.addActionListener(observer); + + f.add(b1); + f.add(b2); + f.add(b3); + + Fond.restoreLastSettings(f); + f.addWindowListener(new CloseListener()); + f.setVisible(true); + } + + public static void restoreLastSettings(JFrame f) { + try (ObjectInputStream fl = new ObjectInputStream(new FileInputStream("save.dat"))) { + try { + int x = fl.readInt(); + int y = fl.readInt(); + int w = fl.readInt(); + int h = fl.readInt(); + + f.setSize(x, y); + f.setLocation(w, h); + + try { + fl.close(); + } catch (IOException e) { + System.out.println(e); + } + } catch (IOException e) { + System.out.println(e); + } + } catch (IOException e) { + System.out.println(e); + } + } +} \ No newline at end of file diff --git a/APL2.1/TP13/Memoire/Observer.class b/APL2.1/TP13/Memoire/Observer.class new file mode 100644 index 0000000..5ca3185 Binary files /dev/null and b/APL2.1/TP13/Memoire/Observer.class differ diff --git a/APL2.1/TP13/Memoire/Observer.java b/APL2.1/TP13/Memoire/Observer.java new file mode 100644 index 0000000..0f416c6 --- /dev/null +++ b/APL2.1/TP13/Memoire/Observer.java @@ -0,0 +1,24 @@ +import java.awt.Color; +import java.awt.event.*; +import javax.swing.JPanel; +import javax.swing.JButton; + +class Observer implements ActionListener { + public Observer() { + + } + + public void actionPerformed(ActionEvent evt) { + String name = evt.getActionCommand(); + JPanel f = (JPanel)((JButton)evt.getSource()).getParent(); + + + if (name == "Jaune") { + f.setBackground(Color.YELLOW); + } else if (name == "Cyan") { + f.setBackground(Color.CYAN); + } else if (name == "Magenta") { + f.setBackground(Color.MAGENTA); + } + } +} \ No newline at end of file diff --git a/APL2.1/TP13/Memoire/save.dat b/APL2.1/TP13/Memoire/save.dat new file mode 100644 index 0000000..e055f0c Binary files /dev/null and b/APL2.1/TP13/Memoire/save.dat differ