diff --git a/APL2.1/TP11/Playlist/Playlist.java b/APL2.1/TP11/Playlist/Playlist.java new file mode 100644 index 0000000..31ae505 --- /dev/null +++ b/APL2.1/TP11/Playlist/Playlist.java @@ -0,0 +1,44 @@ +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 Playlist() { + super(); + } + + public void add(String title) { + JLabel l = new JLabel(title); + l.addMouseListener(this); + l.setOpaque(true); + this.add(l); + } +} \ No newline at end of file diff --git a/APL2.1/TP11/Playlist/TestPlaylist.java b/APL2.1/TP11/Playlist/TestPlaylist.java new file mode 100644 index 0000000..e69de29 diff --git a/APL2.1/TP11/Volume/TestVolume.class b/APL2.1/TP11/Volume/TestVolume.class new file mode 100644 index 0000000..1d0f296 Binary files /dev/null and b/APL2.1/TP11/Volume/TestVolume.class differ diff --git a/APL2.1/TP11/Volume/TestVolume.java b/APL2.1/TP11/Volume/TestVolume.java new file mode 100644 index 0000000..0f34ace --- /dev/null +++ b/APL2.1/TP11/Volume/TestVolume.java @@ -0,0 +1,17 @@ +import java.awt.*; +import javax.swing.*; + +public class TestVolume { + 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); + + Volume v = new Volume(); + v.addMouseWheelListener(v); + + f.add(v); + f.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP11/Volume/Volume.class b/APL2.1/TP11/Volume/Volume.class new file mode 100644 index 0000000..904da5f Binary files /dev/null and b/APL2.1/TP11/Volume/Volume.class differ diff --git a/APL2.1/TP11/Volume/Volume.java b/APL2.1/TP11/Volume/Volume.java new file mode 100644 index 0000000..af09c3a --- /dev/null +++ b/APL2.1/TP11/Volume/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