TP 11 début
This commit is contained in:
parent
67f674b6ef
commit
39ef600e6d
44
APL2.1/TP11/Playlist/Playlist.java
Normal file
44
APL2.1/TP11/Playlist/Playlist.java
Normal 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);
|
||||
}
|
||||
}
|
0
APL2.1/TP11/Playlist/TestPlaylist.java
Normal file
0
APL2.1/TP11/Playlist/TestPlaylist.java
Normal file
BIN
APL2.1/TP11/Volume/TestVolume.class
Normal file
BIN
APL2.1/TP11/Volume/TestVolume.class
Normal file
Binary file not shown.
17
APL2.1/TP11/Volume/TestVolume.java
Normal file
17
APL2.1/TP11/Volume/TestVolume.java
Normal 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);
|
||||
}
|
||||
}
|
BIN
APL2.1/TP11/Volume/Volume.class
Normal file
BIN
APL2.1/TP11/Volume/Volume.class
Normal file
Binary file not shown.
41
APL2.1/TP11/Volume/Volume.java
Normal file
41
APL2.1/TP11/Volume/Volume.java
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user