import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Paintvolume extends JComponent {
  private int volume = 5;
  public Paintvolume() {
    super();
    this.setPreferredSize(new Dimension(500, 100));
  }

  public void upVolume() {
    if (volume != 9) {
      volume++;
      this.repaint();
    }
  }
  public void downVolume() {
    if (volume != 0) {
      volume--;
      this.repaint();
    }
  }

  @Override
  protected void paintComponent(Graphics pinceau) {
    Graphics secondPinceau = pinceau.create();
    if (this.isOpaque()) {
      secondPinceau.setColor(this.getBackground());
      secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
    }
    secondPinceau.setColor(Color.ORANGE);
    int x1, x2;
    for (x1 = 0; x1<volume; x1++) {
      secondPinceau.fillOval( 5*(x1+1) + (this.getWidth()*x1/10) ,25, 50, 50);
    }
    secondPinceau.setColor(Color.GRAY);
    for (x2 = x1; x2<9; x2++) {
      secondPinceau.fillOval( 5*(x2+1) + (this.getWidth()*x2/10) ,25, 50, 50);
    }
  }
}