This commit is contained in:
Adrian POURCHOT 2023-06-07 15:43:38 +02:00
parent b2e4a82bd9
commit 2da42fcdcc
4 changed files with 65 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,17 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Mainvolume{
public static void main(String[] args) {
JFrame fenetre = new JFrame();
Volume pan = new Volume();
fenetre.setSize(1000, 150);
fenetre.setLocation(0, 0);
fenetre.addMouseWheelListener(pan);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setContentPane(pan);
fenetre.setVisible(true);
}
}

Binary file not shown.

View File

@ -0,0 +1,48 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Volume extends JPanel implements MouseWheelListener{
int pos=0;
public Volume(){
super();
}
protected void paintComponent(Graphics pinceau) {
// obligatoire : on cree un nouveau pinceau pour pouvoir le modifier plus tard
Graphics pinceau2 = pinceau.create();
if (this.isOpaque()) {
// obligatoire : on repeint toute la surface avec la couleur de fond
pinceau2.setColor(Color.DARK_GRAY);
pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight());
} for(int i=0; i<pos; i++){
pinceau2.setColor(Color.ORANGE);
pinceau2.fillOval((this.getWidth()/33)+(this.getWidth()/31)*3*i, this.getHeight()/4, (this.getWidth()/31)*2, this.getHeight()/2);
} for(int j=pos; j<10; j++){
pinceau2.setColor(Color.GRAY);
pinceau2.fillOval((this.getWidth()/33)+(this.getWidth()/31)*3*j, this.getHeight()/4, (this.getWidth()/31)*2, this.getHeight()/2);
}
}
public void mouseWheelMoved(MouseWheelEvent e){
int mv = e.getWheelRotation();
if (mv>0){
if(pos==0){
}
else{
pos--;
this.repaint();
}
}
if (mv<0){
if(pos==10){
}
else{
pos++;
this.repaint();
}
}
}
}