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