TP 11 début

This commit is contained in:
HORVILLE 2022-03-28 17:27:59 +02:00
parent 67f674b6ef
commit 39ef600e6d
6 changed files with 102 additions and 0 deletions

View File

@ -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);
}
}

View File

Binary file not shown.

View File

@ -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);
}
}

Binary file not shown.

View File

@ -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();
}
}