update
This commit is contained in:
30
DEV.2.1/TP/TP9-Event..suite/1./Cercle.java
Normal file
30
DEV.2.1/TP/TP9-Event..suite/1./Cercle.java
Normal file
@@ -0,0 +1,30 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Cercle extends JComponent {
|
||||
|
||||
private Color fond;
|
||||
|
||||
public Cercle(Color fond) {
|
||||
this.fond = fond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
|
||||
if (this.isOpaque()) {
|
||||
pinceau.setColor(this.getBackground());
|
||||
pinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
pinceau.setColor(Color.DARK_GRAY);
|
||||
pinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
pinceau.setColor(this.fond);
|
||||
pinceau.fillOval(this.getWidth()/4, this.getHeight()/4, this.getWidth()/2, this.getHeight()/2);
|
||||
}
|
||||
|
||||
public void setFond(Color n) {
|
||||
this.fond = n;
|
||||
}
|
||||
}
|
29
DEV.2.1/TP/TP9-Event..suite/1./Fenetre.java
Normal file
29
DEV.2.1/TP/TP9-Event..suite/1./Fenetre.java
Normal file
@@ -0,0 +1,29 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setSize(700, 100);
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(1, 10));
|
||||
|
||||
Cercle[] tabCercles = new Cercle[10];
|
||||
|
||||
for (int i = 0; i != 5; i++) {
|
||||
Cercle nouveauCercle = new Cercle(Color.ORANGE);
|
||||
this.add(nouveauCercle);
|
||||
tabCercles[i] = nouveauCercle;
|
||||
}
|
||||
|
||||
for (int i = 5; i != 10; i++) {
|
||||
Cercle nouveauCercle = new Cercle(Color.LIGHT_GRAY);
|
||||
this.add(nouveauCercle);
|
||||
tabCercles[i] = nouveauCercle;
|
||||
}
|
||||
|
||||
MoletteSouris gestionSouris = new MoletteSouris(this, tabCercles);
|
||||
this.addMouseWheelListener(gestionSouris);
|
||||
}
|
||||
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Mafenetre extends JFrame {
|
||||
|
||||
public Mafenetre() {
|
||||
super("Volume");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setSize(697,156);
|
||||
this.setLocation(500,250);
|
||||
|
||||
Volume volume = new Volume();
|
||||
this.add(volume);
|
||||
}
|
||||
|
||||
}
|
6
DEV.2.1/TP/TP9-Event..suite/1./Main.java
Normal file
6
DEV.2.1/TP/TP9-Event..suite/1./Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -1,10 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MainVolume {
|
||||
public static void main(String[] args) {
|
||||
Mafenetre fenetre = new Mafenetre();
|
||||
fenetre.setVisible(true);
|
||||
|
||||
}
|
||||
}
|
38
DEV.2.1/TP/TP9-Event..suite/1./MoletteSouris.java
Normal file
38
DEV.2.1/TP/TP9-Event..suite/1./MoletteSouris.java
Normal file
@@ -0,0 +1,38 @@
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class MoletteSouris implements MouseWheelListener {
|
||||
|
||||
private Fenetre fenetre;
|
||||
private Cercle[] tabCercles;
|
||||
private int depart;
|
||||
|
||||
public MoletteSouris(Fenetre fenetre, Cercle[] tabCercles) {
|
||||
this.fenetre = fenetre;
|
||||
this.tabCercles = tabCercles;
|
||||
this.depart = 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent evenement) {
|
||||
int sensRotation = evenement.getWheelRotation();
|
||||
this.depart -= sensRotation;
|
||||
|
||||
if (this.depart == 11) {
|
||||
this.depart = 10;
|
||||
}
|
||||
else if (this.depart == -1) {
|
||||
this.depart = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.depart ; i++) {
|
||||
this.tabCercles[i].setFond(Color.ORANGE);
|
||||
}
|
||||
for (int i = this.depart; i < 10; i++) {
|
||||
this.tabCercles[i].setFond(Color.LIGHT_GRAY);
|
||||
}
|
||||
this.fenetre.repaint();
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -1,16 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MouseWheel implements MouseWheelListener {
|
||||
|
||||
public MouseWheel() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent evenement) {
|
||||
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
@@ -1,36 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Volume extends JComponent {
|
||||
private int niveau = 5;
|
||||
|
||||
public Volume() {
|
||||
super();
|
||||
}
|
||||
|
||||
public setNiveau(int newNiveau) {
|
||||
if (newNiveau < 0) {
|
||||
this.niveau = 0;
|
||||
} else if (newNiveau > 10) {
|
||||
this.niveau = 10;
|
||||
} else {
|
||||
this.niveau = newNiveau;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public int getNiveau() {
|
||||
return this.niveau;
|
||||
}
|
||||
|
||||
@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.setBackground(Color.BLUE);
|
||||
}
|
||||
|
||||
}
|
BIN
DEV.2.1/TP/TP9-Event..suite/2./Fenetre.class
Normal file
BIN
DEV.2.1/TP/TP9-Event..suite/2./Fenetre.class
Normal file
Binary file not shown.
13
DEV.2.1/TP/TP9-Event..suite/2./Fenetre.java
Normal file
13
DEV.2.1/TP/TP9-Event..suite/2./Fenetre.java
Normal file
@@ -0,0 +1,13 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setSize(800, 500);
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
GestionSouris clicSouris = new GestionSouris(this);
|
||||
this.addMouseListener(clicSouris);
|
||||
this.addMouseMotionListener(new GestionMouvementSouris(this, clicSouris));
|
||||
}
|
||||
}
|
BIN
DEV.2.1/TP/TP9-Event..suite/2./GestionMouvementSouris.class
Normal file
BIN
DEV.2.1/TP/TP9-Event..suite/2./GestionMouvementSouris.class
Normal file
Binary file not shown.
24
DEV.2.1/TP/TP9-Event..suite/2./GestionMouvementSouris.java
Normal file
24
DEV.2.1/TP/TP9-Event..suite/2./GestionMouvementSouris.java
Normal file
@@ -0,0 +1,24 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class GestionMouvementSouris implements MouseMotionListener {
|
||||
|
||||
private Fenetre fenetre;
|
||||
private GestionSouris clicSouris;
|
||||
|
||||
public GestionMouvementSouris(Fenetre fenetre, GestionSouris clicSouris) {
|
||||
this.fenetre = fenetre;
|
||||
this.clicSouris = clicSouris;
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
System.out.println("Appuyé");
|
||||
this.clicSouris.setRect(e.getX(), e.getY());
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
System.out.println("Relâché");
|
||||
}
|
||||
}
|
BIN
DEV.2.1/TP/TP9-Event..suite/2./GestionSouris.class
Normal file
BIN
DEV.2.1/TP/TP9-Event..suite/2./GestionSouris.class
Normal file
Binary file not shown.
55
DEV.2.1/TP/TP9-Event..suite/2./GestionSouris.java
Normal file
55
DEV.2.1/TP/TP9-Event..suite/2./GestionSouris.java
Normal file
@@ -0,0 +1,55 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GestionSouris implements MouseListener {
|
||||
|
||||
private Fenetre fenetre;
|
||||
private JPanel rect;
|
||||
private int debutX;
|
||||
private int debutY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
private boolean rectActif;
|
||||
|
||||
public GestionSouris(Fenetre fenetre) {
|
||||
this.fenetre = fenetre;
|
||||
this.rectActif = false;
|
||||
}
|
||||
|
||||
|
||||
public void mouseClicked(MouseEvent evenement) {
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent evenement){
|
||||
if (this.rectActif) {
|
||||
this.fenetre.remove(this.rect);
|
||||
}
|
||||
System.out.println("Appui simple");
|
||||
this.rect = new JPanel();
|
||||
this.rect.setOpaque(true);
|
||||
this.rect.setBackground(Color.BLUE);
|
||||
this.debutX = evenement.getX()-4; // Le -4 est du à un décalage de la méthode getX jsp pourquoi sah
|
||||
this.debutY = evenement.getY()-26; // Pareil pour le -26
|
||||
this.fenetre.add(this.rect);
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent evenement){
|
||||
this.rectActif = true;
|
||||
}
|
||||
|
||||
public void setRect(int finX, int finY) {
|
||||
System.out.println(this.debutX + " " + this.debutY + " " + (finX-this.debutX+5) + " " + (finY-this.debutY-10) + "");
|
||||
this.rect.setBounds(this.debutX, this.debutY, finX-this.debutX-4, finY-this.debutY-26); // Décalage encore
|
||||
//System.out.println("debut : [" + this.debutX + ", " + this.debutY + "]");
|
||||
//System.out.println("fin : [" + finX + ", " + finY + "]");
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
}
|
BIN
DEV.2.1/TP/TP9-Event..suite/2./Main.class
Normal file
BIN
DEV.2.1/TP/TP9-Event..suite/2./Main.class
Normal file
Binary file not shown.
6
DEV.2.1/TP/TP9-Event..suite/2./Main.java
Normal file
6
DEV.2.1/TP/TP9-Event..suite/2./Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV.2.1/TP/TP9-Event..suite/2./Rect.class
Normal file
BIN
DEV.2.1/TP/TP9-Event..suite/2./Rect.class
Normal file
Binary file not shown.
29
DEV.2.1/TP/TP9-Event..suite/2./Rect.java
Normal file
29
DEV.2.1/TP/TP9-Event..suite/2./Rect.java
Normal file
@@ -0,0 +1,29 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Rect extends JComponent {
|
||||
|
||||
private int departX;
|
||||
private int departY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
|
||||
public Rect(int departX, int departY, int finX, int finY) {
|
||||
this.departX = departX;
|
||||
this.departY = departY;
|
||||
this.finX = finX;
|
||||
this.finY = finY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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.BLUE);
|
||||
secondPinceau.fillRect(this.departX, this.departY, this.finX-this.departX, this.finY-this.departY);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user