push
This commit is contained in:
33
DEV2.1/TP09/Exo1/Cercles.java
Normal file
33
DEV2.1/TP09/Exo1/Cercles.java
Normal file
@@ -0,0 +1,33 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
public class Cercles extends JComponent {
|
||||
private int i;
|
||||
public Cercles(){
|
||||
super();
|
||||
}
|
||||
|
||||
public void getNombre(int a){
|
||||
this.i=a;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics pinceau){
|
||||
Graphics pinpin=pinceau.create();
|
||||
if(this.isOpaque()){
|
||||
pinpin.setColor(this.getBackground());
|
||||
pinpin.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
for (int j = 0; j < this.i; j++) {
|
||||
pinpin.setColor(Color.YELLOW);
|
||||
pinpin.fillOval(j*30, this.getHeight()/2, 20, 20);
|
||||
}
|
||||
for (int j=this.i; j < 10; j++) {
|
||||
pinpin.setColor(Color.GRAY);
|
||||
pinpin.fillOval(j*30, this.getHeight()/2, 20, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
DEV2.1/TP09/Exo1/Volume.java
Normal file
17
DEV2.1/TP09/Exo1/Volume.java
Normal file
@@ -0,0 +1,17 @@
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class Volume {
|
||||
public static void main(String[] args) {
|
||||
JFrame fenetre=new JFrame();
|
||||
fenetre.setSize(500,100);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Cercles test=new Cercles();
|
||||
VolumeAct stiti=new VolumeAct(test);
|
||||
|
||||
fenetre.addMouseWheelListener(stiti);
|
||||
fenetre.add(test);
|
||||
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
25
DEV2.1/TP09/Exo1/VolumeAct.java
Normal file
25
DEV2.1/TP09/Exo1/VolumeAct.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import java.awt.event.*;
|
||||
|
||||
public class VolumeAct implements MouseWheelListener {
|
||||
private int a;
|
||||
private Cercles ce;
|
||||
public VolumeAct(Cercles chat){
|
||||
super();
|
||||
this.a=0;
|
||||
this.ce=chat;
|
||||
}
|
||||
|
||||
public void mouseWheelMoved(MouseWheelEvent e){
|
||||
int i;
|
||||
i=e.getWheelRotation();
|
||||
if(i<0 && this.a<10){
|
||||
this.a++;
|
||||
ce.getNombre(this.a);
|
||||
}
|
||||
|
||||
if(i>0 && this.a>0){
|
||||
this.a--;
|
||||
ce.getNombre(this.a);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user