diff --git a/APL2.1/TP11/Playlist/Observer.class b/APL2.1/TP11/Playlist/Observer.class new file mode 100644 index 0000000..1b2555c Binary files /dev/null and b/APL2.1/TP11/Playlist/Observer.class differ diff --git a/APL2.1/TP11/Playlist/Observer.java b/APL2.1/TP11/Playlist/Observer.java new file mode 100644 index 0000000..e40b258 --- /dev/null +++ b/APL2.1/TP11/Playlist/Observer.java @@ -0,0 +1,40 @@ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +public class Observer implements MouseListener { + private JLabel prevSelected; + + public void mouseClicked(MouseEvent evenement) { + JLabel lb = (JLabel)evenement.getSource(); + if (prevSelected != null) { + prevSelected.setBackground(new Color(255, 255, 255)); + } + + lb.setBackground(new Color(0, 255, 255)); + prevSelected = lb; + } + + public void mouseEntered(MouseEvent evenement) { + JLabel lb = (JLabel)evenement.getSource(); + + if (lb == prevSelected) { + lb.setBackground(new Color(0, 255, 255)); + } else { + lb.setBackground(new Color(200, 200, 200)); + } + } + + public void mouseExited(MouseEvent evenement) { + JLabel lb = (JLabel)evenement.getSource(); + + if (lb == prevSelected) { + lb.setBackground(new Color(0, 200, 255)); + } else { + lb.setBackground(new Color(255, 255, 255)); + } + } + + public void mousePressed(MouseEvent evenement) {} + public void mouseReleased(MouseEvent evenement) {} +} \ No newline at end of file diff --git a/APL2.1/TP11/Playlist/Playlist.class b/APL2.1/TP11/Playlist/Playlist.class new file mode 100644 index 0000000..ac0f366 Binary files /dev/null and b/APL2.1/TP11/Playlist/Playlist.class differ diff --git a/APL2.1/TP11/Playlist/Playlist.java b/APL2.1/TP11/Playlist/Playlist.java index 31ae505..e1c5870 100644 --- a/APL2.1/TP11/Playlist/Playlist.java +++ b/APL2.1/TP11/Playlist/Playlist.java @@ -2,42 +2,22 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; -public class Playlist extends JPanel implements MouseListener { - private JLabel prevSelection; - private JLabel prevHover; - - public void mouseClicked(MouseEvent evenement) { - JLabel raiser = evenement.getComponent(); - raiser.setBackground(new Color(0, 150, 255)); - - if (prevSelection != null) { - prevSelection.setBackground(new Color(255, 255, 255)); - } - } - - public void mouseEntered(MouseEvent evenement) { - - } - - public void mouseExited(MouseEvent evenement) { - - } - - public void mousePressed(MouseEvent evenement) {} - public void mouseReleased(MouseEvent evenement) {} - - @Override - public void paintComponent(Graphics brush) { - - } +public class Playlist extends JPanel { + private int elementCount; + private Observer obs; public Playlist() { super(); + elementCount = 0; + obs = new Observer(); } public void add(String title) { + elementCount += 1; + this.setLayout(new GridLayout(elementCount, 1)); + JLabel l = new JLabel(title); - l.addMouseListener(this); + l.addMouseListener(obs); l.setOpaque(true); this.add(l); } diff --git a/APL2.1/TP11/Playlist/TestPlaylist.class b/APL2.1/TP11/Playlist/TestPlaylist.class new file mode 100644 index 0000000..5d9af3f Binary files /dev/null and b/APL2.1/TP11/Playlist/TestPlaylist.class differ diff --git a/APL2.1/TP11/Playlist/TestPlaylist.java b/APL2.1/TP11/Playlist/TestPlaylist.java index e69de29..ce147e7 100644 --- a/APL2.1/TP11/Playlist/TestPlaylist.java +++ b/APL2.1/TP11/Playlist/TestPlaylist.java @@ -0,0 +1,25 @@ +import java.awt.*; +import javax.swing.*; + +public class TestPlaylist { + public static void main(String[] args) { + JFrame f = new JFrame("Fond"); + f.setSize(200, 210); + f.setLocation(100, 100); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + Playlist p = new Playlist(); + p.add("Speak To Me / Breathe"); + p.add("On The Run"); + p.add("Time"); + p.add("The Great Gig In The Sky"); + p.add("Money"); + p.add("Us and Them"); + p.add("Any Colour You Like"); + p.add("Brain Damage"); + p.add("Eclipse"); + + f.add(p); + f.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP11/Rectangle/Observer.java b/APL2.1/TP11/Rectangle/Observer.java new file mode 100644 index 0000000..54a2201 --- /dev/null +++ b/APL2.1/TP11/Rectangle/Observer.java @@ -0,0 +1,26 @@ +public class Observer implements MouseMotionListener, MouseListener { + public Observer() {} + + void mouseClicked(MouseEvent evenement) {} + void mouseEntered(MouseEvent evenement) {} + void mouseExited(MouseEvent evenement) {} + void mouseMoved(MouseEvent evenement) {} + + void mousePressed(MouseEvent evenement) { + Rectangle rect = (Rectangle)evenement.getSource(); + rect.SetX(evenement.getX()); + rect.SetY(evenement.getY()); + rect.ShouldDraw(true); + } + + void mouseReleased(MouseEvent evenement) { + Rectangle rect = (Rectangle)evenement.getSource(); + rect.ShouldDraw(false); + } + + void mouseDragged(MouseEvent evenement) { + Rectangle rect = (Rectangle)evenement.getSource(); + rect.SetSX(evenement.getX()); + rect.SetSY(evenement.getY()); + } +} \ No newline at end of file diff --git a/APL2.1/TP11/Rectangle/Rectangle.java b/APL2.1/TP11/Rectangle/Rectangle.java new file mode 100644 index 0000000..690284d --- /dev/null +++ b/APL2.1/TP11/Rectangle/Rectangle.java @@ -0,0 +1,62 @@ +public class Rectangle extends JComponent { + private int X; + private int Y; + private int SX; + private int SY; + private boolean shouldDraw; + + public Rectangle() { + shouldDraw = false; + X = 0; + Y = 0; + SX = 0; + SY = 0; + } + + public void SetX(int X) { + this.X = X; + } + + public void SetY(int Y) { + this.Y = Y; + } + + public void SetSX(int SX) { + this.SX = SX; + } + + public void SetSY(int SY) { + this.SY = SY; + } + + public void ShouldDraw(boolean shouldDraw) { + this.shouldDraw = shouldDraw; + } + + @Override + protected void paintComponent(Graphics brush) { + Graphics newBrush = brush.create(); + + if (this.isOpaque()) { + newBrush.setColor(this.getBackground()); + newBrush.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + + if (this.shouldDraw) { + newBrush.setColor(new Color(0, 220, 255)); + if (X < SX) { + int buff = X; + X = SX; + SX = buff; + } + + if (Y < SY) { + int buff = Y; + Y = SY; + SY = buff; + } + + + } + } +} \ No newline at end of file diff --git a/APL2.1/TP11/Rectangle/TestRectangle.java b/APL2.1/TP11/Rectangle/TestRectangle.java new file mode 100644 index 0000000..fdac8b8 --- /dev/null +++ b/APL2.1/TP11/Rectangle/TestRectangle.java @@ -0,0 +1,12 @@ +public class TestRectangle { + public static void main(String[] args) { + JFrame f = new JFrame("Fond"); + f.setSize(700, 200); + f.setLocation(100, 100); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + Rectangle r = new Rectangle(); + r.addMouseMotionListener(new Observer()); + f.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Apparences/Apparences.class b/APL2.1/TP12/Apparences/Apparences.class new file mode 100644 index 0000000..1b91f50 Binary files /dev/null and b/APL2.1/TP12/Apparences/Apparences.class differ diff --git a/APL2.1/TP12/Apparences/Apparences.java b/APL2.1/TP12/Apparences/Apparences.java new file mode 100644 index 0000000..72ac66f --- /dev/null +++ b/APL2.1/TP12/Apparences/Apparences.java @@ -0,0 +1,62 @@ +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; + +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); + } + } +} + +public class Apparences { + + public static void main(String[] args) { + try { + UIManager.setLookAndFeel("toto"); + } catch (ClassNotFoundException e) { + System.err.println("CONCENTRE TOI NOM DE DIEU !!"); + + } catch (ClassCastException e) { + System.err.println("Tu pourrais te concentrer et coder bien ?"); + + } catch (Exception e) { + System.err.println("Prout !"); + } + + 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); + + f.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Apparences/Observer.class b/APL2.1/TP12/Apparences/Observer.class new file mode 100644 index 0000000..2faf9fd Binary files /dev/null and b/APL2.1/TP12/Apparences/Observer.class differ diff --git a/APL2.1/TP12/Apparences/Volume.class b/APL2.1/TP12/Apparences/Volume.class new file mode 100644 index 0000000..904da5f Binary files /dev/null and b/APL2.1/TP12/Apparences/Volume.class differ diff --git a/APL2.1/TP12/Apparences/Volume.java b/APL2.1/TP12/Apparences/Volume.java new file mode 100644 index 0000000..af09c3a --- /dev/null +++ b/APL2.1/TP12/Apparences/Volume.java @@ -0,0 +1,41 @@ +import java.awt.*; +import java.awt.event.*; + +import javax.swing.*; + +public class Volume extends JComponent implements MouseWheelListener { + private static final int margin = 10; + private static final int numCircles = 10; + private int currentLevel = 0; + + public void mouseWheelMoved(MouseWheelEvent ev) { + currentLevel -= ev.getWheelRotation(); + currentLevel = Math.max(0, Math.min(currentLevel, 11)); + repaint(); + } + + @Override + protected void paintComponent(Graphics brush) { + Graphics newBrush = brush.create(); + + if (this.isOpaque()) { + newBrush.setColor(this.getBackground()); + newBrush.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + + newBrush.setColor(new Color(50, 50, 50)); + newBrush.fillRect(0, 0, getWidth(), getHeight()); + + + for (int i = 0; i < numCircles; i++) { + if (currentLevel > i) newBrush.setColor(new Color(230, 170, 0)); + else newBrush.setColor(new Color(200, 200, 200)); + + newBrush.fillOval(margin + (getWidth() - margin * 2) / numCircles * i, getHeight() / 2, getHeight() / 4, getHeight() / 4); + } + } + + public Volume() { + super(); + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Capture/Arithmetic.class b/APL2.1/TP12/Capture/Arithmetic.class new file mode 100644 index 0000000..4fbe1cb Binary files /dev/null and b/APL2.1/TP12/Capture/Arithmetic.class differ diff --git a/APL2.1/TP12/Capture/Arithmetic.java b/APL2.1/TP12/Capture/Arithmetic.java new file mode 100644 index 0000000..d4e6994 --- /dev/null +++ b/APL2.1/TP12/Capture/Arithmetic.java @@ -0,0 +1,13 @@ +public class Arithmetic { + public static void crash() { + System.out.println(1 / 0); + } + + public static void main(String[] args) { + try { + crash(); + } catch (ArithmeticException e) { + System.err.println(e); + } + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Degrés/Degres.class b/APL2.1/TP12/Degrés/Degres.class new file mode 100644 index 0000000..d1d88b1 Binary files /dev/null and b/APL2.1/TP12/Degrés/Degres.class differ diff --git a/APL2.1/TP12/Degrés/Degres.java b/APL2.1/TP12/Degrés/Degres.java new file mode 100644 index 0000000..79c697d --- /dev/null +++ b/APL2.1/TP12/Degrés/Degres.java @@ -0,0 +1,44 @@ +import java.awt.*; +import javax.swing.*; + +public class Degres { + public static void main(String[] args) { + JFrame f = new JFrame("Degrés !"); + f.setSize(300, 150); + f.setLocation(100, 100); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setLayout(null); + + JTextField CC = new JTextField(); + JTextField CF = new JTextField(); + + JLabel LC = new JLabel("°C"); + JLabel LF = new JLabel("°F"); + + LC.setSize(20, 20); + LF.setSize(20, 20); + + LC.setLocation(230, 30); + LF.setLocation(230, 60); + + CC.setSize(200, 20); + CF.setSize(200, 20); + + CC.setLocation(20, 30); + CF.setLocation(20, 60); + + Observer obs1 = new Observer(false); + Observer obs2 = new Observer(true); + obs1.setOutputField(CF); + obs2.setOutputField(CC); + + CC.addActionListener(obs1); + CF.addActionListener(obs2); + + f.add(LC); + f.add(LF); + f.add(CF); + f.add(CC); + f.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Degrés/Observer.class b/APL2.1/TP12/Degrés/Observer.class new file mode 100644 index 0000000..742fbcb Binary files /dev/null and b/APL2.1/TP12/Degrés/Observer.class differ diff --git a/APL2.1/TP12/Degrés/Observer.java b/APL2.1/TP12/Degrés/Observer.java new file mode 100644 index 0000000..1c33e33 --- /dev/null +++ b/APL2.1/TP12/Degrés/Observer.java @@ -0,0 +1,35 @@ +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; + +public class Observer implements ActionListener { + private JTextField outputField; + private boolean toDeg; + + public Observer(boolean toDeg) { + this.toDeg = toDeg; + } + + public void setOutputField(JTextField f) { + outputField = f; + } + + public void actionPerformed(ActionEvent ev) { + try { + float temp = Float.parseFloat(ev.getActionCommand()); + + if (toDeg) { + temp -= 32f; + temp *= 5f/9f; + } else { + temp *= 9f/5f; + temp += 32f; + } + + outputField.setText(Float.toString(temp)); + + } catch (NumberFormatException ex) { + outputField.setText("???"); + } + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Incomplet/Incomplet.class b/APL2.1/TP12/Incomplet/Incomplet.class new file mode 100644 index 0000000..ac1bd7f Binary files /dev/null and b/APL2.1/TP12/Incomplet/Incomplet.class differ diff --git a/APL2.1/TP12/Incomplet/Incomplet.java b/APL2.1/TP12/Incomplet/Incomplet.java new file mode 100644 index 0000000..8fd2e98 --- /dev/null +++ b/APL2.1/TP12/Incomplet/Incomplet.java @@ -0,0 +1,13 @@ +import java.io.*; + +public class Incomplet { + public static void main(String[] args) { + try { + byte[] txt = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x0D, 0x0A}; + System.out.write(txt); + } catch (IOException e) { + System.err.println(e); + } + + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Plantages/Arithmetic.class b/APL2.1/TP12/Plantages/Arithmetic.class new file mode 100644 index 0000000..4c37d8b Binary files /dev/null and b/APL2.1/TP12/Plantages/Arithmetic.class differ diff --git a/APL2.1/TP12/Plantages/Arithmetic.java b/APL2.1/TP12/Plantages/Arithmetic.java new file mode 100644 index 0000000..73807ef --- /dev/null +++ b/APL2.1/TP12/Plantages/Arithmetic.java @@ -0,0 +1,5 @@ +public class Arithmetic { + public static void main(String[] args) { + System.out.println( 1 / 0 ); + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Plantages/ArrayIndex.class b/APL2.1/TP12/Plantages/ArrayIndex.class new file mode 100644 index 0000000..3f156f8 Binary files /dev/null and b/APL2.1/TP12/Plantages/ArrayIndex.class differ diff --git a/APL2.1/TP12/Plantages/ArrayIndex.java b/APL2.1/TP12/Plantages/ArrayIndex.java new file mode 100644 index 0000000..299c565 --- /dev/null +++ b/APL2.1/TP12/Plantages/ArrayIndex.java @@ -0,0 +1,5 @@ +public class ArrayIndex { + public static void main(String[] args) { + System.out.println(args[args.length]); + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Plantages/NullPointer.class b/APL2.1/TP12/Plantages/NullPointer.class new file mode 100644 index 0000000..7c4cb1c Binary files /dev/null and b/APL2.1/TP12/Plantages/NullPointer.class differ diff --git a/APL2.1/TP12/Plantages/NullPointer.java b/APL2.1/TP12/Plantages/NullPointer.java new file mode 100644 index 0000000..78d9893 --- /dev/null +++ b/APL2.1/TP12/Plantages/NullPointer.java @@ -0,0 +1,6 @@ +public class NullPointer { + public static void main(String[] args) { + String s = null; + s.charAt(1); + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Plantages/NumberFormat.class b/APL2.1/TP12/Plantages/NumberFormat.class new file mode 100644 index 0000000..f6d9c7a Binary files /dev/null and b/APL2.1/TP12/Plantages/NumberFormat.class differ diff --git a/APL2.1/TP12/Plantages/NumberFormat.java b/APL2.1/TP12/Plantages/NumberFormat.java new file mode 100644 index 0000000..dfc3646 --- /dev/null +++ b/APL2.1/TP12/Plantages/NumberFormat.java @@ -0,0 +1,5 @@ +public class NumberFormat { + public static void main(String[] args) { + Integer.parseInt("owo"); + } +} \ No newline at end of file diff --git a/APL2.1/TP12/Plantages/Runtime.class b/APL2.1/TP12/Plantages/Runtime.class new file mode 100644 index 0000000..0985dee Binary files /dev/null and b/APL2.1/TP12/Plantages/Runtime.class differ diff --git a/APL2.1/TP12/Plantages/Runtime.java b/APL2.1/TP12/Plantages/Runtime.java new file mode 100644 index 0000000..c86c196 --- /dev/null +++ b/APL2.1/TP12/Plantages/Runtime.java @@ -0,0 +1,5 @@ +public class Runtime { + public static void main(String[] args) { + throw new RuntimeException("OwO"); + } +} \ No newline at end of file