update
This commit is contained in:
14
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Action.java~
Normal file
14
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Action.java~
Normal file
@@ -0,0 +1,14 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Action implements MouseListener{
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e){
|
||||
System.out.println("mouseDragged");
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e){
|
||||
System.out.println("mouseReleased");
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Barre.class
Normal file
BIN
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Barre.class
Normal file
Binary file not shown.
19
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Barre.java
Normal file
19
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Barre.java
Normal file
@@ -0,0 +1,19 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Barre{
|
||||
public static void main(String[] args) {
|
||||
|
||||
Rectangle test = new Rectangle();
|
||||
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(800, 800);
|
||||
fenetre.setLocation(100, 100);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.add(test);
|
||||
test.addMouseListener(test);
|
||||
test.addMouseMotionListener(test);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
18
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Barre.java~
Normal file
18
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Barre.java~
Normal file
@@ -0,0 +1,18 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Barre{
|
||||
public static void main(String[] args) {
|
||||
|
||||
Rectangle test = new Rectangle();
|
||||
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(800, 800);
|
||||
fenetre.setLocation(100, 100);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.add(test);
|
||||
test.addMouseListener(new Action());
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public interface MouseListener{
|
||||
void mousePressed(MouseEvent evenement);
|
||||
void mouseReleased(MouseEvent evenement);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public interface MouseMotionListener{
|
||||
void mouseDragged(MouseWheelEvent evenement);
|
||||
void mouseMoved(MouseWheelEvent evenement);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
public interface MouseWheelMoved{
|
||||
void mouseWheelMoved(MouseWheelEvent evenement);
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Rectangle.class
Normal file
BIN
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Rectangle.class
Normal file
Binary file not shown.
81
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Rectangle.java
Normal file
81
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Rectangle.java
Normal file
@@ -0,0 +1,81 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
public class Rectangle extends JComponent implements MouseMotionListener,MouseListener{
|
||||
int xOrigine;
|
||||
int yOrigine;
|
||||
int yFinal;
|
||||
int xFinal;
|
||||
int longueurFenetre;
|
||||
int hauteurFenetre;
|
||||
|
||||
public Rectangle(){
|
||||
this.xOrigine = -1;
|
||||
this.yOrigine = -1;
|
||||
this.xFinal = -1;
|
||||
this.yFinal = -1;
|
||||
this.longueurFenetre = this.getWidth();
|
||||
this.hauteurFenetre = this.getHeight();
|
||||
}
|
||||
|
||||
@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(0,255,100));
|
||||
|
||||
if (this.xOrigine >= 0 && this.yOrigine >= 0){
|
||||
int newXOrigine;
|
||||
int newYOrigine;
|
||||
int newLongueur;
|
||||
int newHauteur;
|
||||
if (xFinal >= xOrigine){
|
||||
newXOrigine = this.getWidth()*this.xOrigine/this.longueurFenetre;
|
||||
newLongueur = this.getWidth()*(this.xFinal-this.xOrigine)/this.longueurFenetre;
|
||||
}
|
||||
else{
|
||||
newXOrigine = this.getWidth()*this.xFinal/this.longueurFenetre;
|
||||
newLongueur = this.getWidth()*(this.xOrigine-this.xFinal)/this.longueurFenetre;
|
||||
}
|
||||
if (yFinal >= yOrigine){
|
||||
newYOrigine = this.getHeight()*this.yOrigine/this.hauteurFenetre;
|
||||
newHauteur = this.getHeight()*(this.yFinal-this.yOrigine)/this.hauteurFenetre;
|
||||
}
|
||||
else{
|
||||
newYOrigine = this.getHeight()*this.yFinal/this.hauteurFenetre;
|
||||
newHauteur = this.getHeight()*(this.yOrigine-this.yFinal)/this.hauteurFenetre;
|
||||
}
|
||||
secondPinceau.fillRect(newXOrigine,newYOrigine,newLongueur,newHauteur);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e){
|
||||
this.xFinal = e.getX();
|
||||
this.yFinal = e.getY();
|
||||
repaint();
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e){
|
||||
this.longueurFenetre = this.getWidth();
|
||||
this.hauteurFenetre = this.getHeight();
|
||||
this.xOrigine = e.getX();
|
||||
this.yOrigine = e.getY();
|
||||
}
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e){
|
||||
}
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e){
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e){
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e){
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e){
|
||||
}
|
||||
}
|
||||
36
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Rectangle.java~
Normal file
36
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Rectangle.java~
Normal file
@@ -0,0 +1,36 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
public class Rectangle extends JComponent{
|
||||
int xOrigine;
|
||||
int yOrigine;
|
||||
int yDestination;
|
||||
int xDestination;
|
||||
int longueurFenetre;
|
||||
int hauteurFenetre;
|
||||
|
||||
public Rectangle(){
|
||||
this.xOrigine = -1;
|
||||
this.yOrigine = -1;
|
||||
this.xDestination = -1;
|
||||
this.yDestination = -1;
|
||||
this.longueurFenetre = this.getWidth();
|
||||
this.hauteurFenetre = this.getHeight();
|
||||
}
|
||||
|
||||
@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(0,255,100));
|
||||
|
||||
if (this.xOrigine >= 0 && this.yOrigine >= 0){
|
||||
int newXOrigine = this.getWidth()*this.xOrigine/this.longueurFenetre;
|
||||
int newYOrigine = this.getHeight()*this.yOrigine/this.hauteurFenetre;
|
||||
int newLongueur = this.getWidth()*(this.xDestination-this.xOrigine)/this.longueurFenetre;
|
||||
int newHauteur = this.getHeight()*(this.yDestination-this.yOrigine)/this.hauteurFenetre;
|
||||
secondPinceau.fillRect(newXOrigine,newXOrigine,newLongueur,newHauteur);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Rond.java~
Normal file
46
DEV/DEV2.1/TP09_Evenement2/Q3_Rectangle/Rond.java~
Normal file
@@ -0,0 +1,46 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
public class Rond extends JComponent implements MouseWheelListener{
|
||||
public int nbRond;
|
||||
public int valeur;
|
||||
public double tailleRond;
|
||||
|
||||
public Rond(int nbRond){
|
||||
this.nbRond = nbRond;
|
||||
this.valeur = 0;
|
||||
this.tailleRond = 0.8;
|
||||
}
|
||||
|
||||
@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(0,255,100));
|
||||
int unite = this.getWidth() / this.nbRond;
|
||||
int diametre = (int) ((double) unite * tailleRond);
|
||||
int ordonnee = (getHeight()-diametre)/2;
|
||||
for (int i=0; i<this.nbRond; i++){
|
||||
if (this.valeur <= i){
|
||||
secondPinceau.setColor(new Color(100,0,255));
|
||||
}
|
||||
secondPinceau.fillOval(i*unite+(unite-diametre)/2, ordonnee,diametre,diametre);
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseWheelMoved(MouseWheelEvent e){
|
||||
if (e.getWheelRotation() < 0) {
|
||||
if (this.valeur<10){
|
||||
this.valeur++;
|
||||
repaint();
|
||||
}
|
||||
} else {
|
||||
if (this.valeur>0){
|
||||
this.valeur--;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user