BUT2/DEV/DEV2.1/TP09_Evenement2/Rond.java~

33 lines
865 B
Java
Raw Normal View History

2023-10-23 13:23:36 +02:00
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Rond extends JComponent implements MouseWheelListener{
public int nbRond;
public Rond(int nbRond){
this.nbRond = nbRond;
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
secondPinceau.setColor(new Color(0,0,0));
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
secondPinceau.setColor(new Color(255,255,255));
int x = this.getWidth()/this.nbRond;
for (int i=1; i<=this.nbRond; i++){
secondPinceau.fillOval(i*x-x/2, this.getHeight()/2,50,50);
}
}
public void mouseWheelMoved(MouseWheelEvent e){
if (e.getWheelRotation() < 0) {
System.out.println("mouse wheel Up");
} else {
System.out.println("mouse wheel Down");
}
}
}