TP Exceptions
This commit is contained in:
BIN
DEV2.1/TP09/03_Rectangle/Fenetre.class
Normal file
BIN
DEV2.1/TP09/03_Rectangle/Fenetre.class
Normal file
Binary file not shown.
13
DEV2.1/TP09/03_Rectangle/Fenetre.java
Normal file
13
DEV2.1/TP09/03_Rectangle/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
DEV2.1/TP09/03_Rectangle/GestionMouvementSouris.class
Normal file
BIN
DEV2.1/TP09/03_Rectangle/GestionMouvementSouris.class
Normal file
Binary file not shown.
24
DEV2.1/TP09/03_Rectangle/GestionMouvementSouris.java
Normal file
24
DEV2.1/TP09/03_Rectangle/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
DEV2.1/TP09/03_Rectangle/GestionSouris.class
Normal file
BIN
DEV2.1/TP09/03_Rectangle/GestionSouris.class
Normal file
Binary file not shown.
57
DEV2.1/TP09/03_Rectangle/GestionSouris.java
Normal file
57
DEV2.1/TP09/03_Rectangle/GestionSouris.java
Normal file
@@ -0,0 +1,57 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GestionSouris implements MouseListener {
|
||||
|
||||
private Fenetre fenetre;
|
||||
private Rectangle rect;
|
||||
private int debutX;
|
||||
private int debutY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
|
||||
public GestionSouris(Fenetre fenetre) {
|
||||
this.fenetre = fenetre;
|
||||
}
|
||||
|
||||
|
||||
public void mouseClicked(MouseEvent evenement) {
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent evenement){
|
||||
System.out.println("Appui simple");
|
||||
this.fenetre.add(new Rectangle(evenement.getX(), evenement.getY(), evenement.getX()+200, evenement.getY()+200));
|
||||
this.debutX = evenement.getX();
|
||||
this.debutY = evenement.getY();
|
||||
this.rect = new Rectangle(this.debutX, this.debutY, evenement.getX(), evenement.getY());
|
||||
//this.fenetre.add(rect);
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent evenement){
|
||||
this.finX = evenement.getX();
|
||||
this.finY = evenement.getY();
|
||||
}
|
||||
|
||||
public int getDebutX() {
|
||||
return this.debutX;
|
||||
}
|
||||
|
||||
public int getDebutY() {
|
||||
return this.debutY;
|
||||
}
|
||||
|
||||
public void setRect(int finX, int finY) {
|
||||
this.rect.setBounds(this.debutX, this.debutY, finX, finY);
|
||||
System.out.println("debut : [" + this.debutX + ", " + this.debutY + "]");
|
||||
System.out.println("fin : [" + finX + ", " + finY + "]");
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/03_Rectangle/Main.class
Normal file
BIN
DEV2.1/TP09/03_Rectangle/Main.class
Normal file
Binary file not shown.
6
DEV2.1/TP09/03_Rectangle/Main.java
Normal file
6
DEV2.1/TP09/03_Rectangle/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
DEV2.1/TP09/03_Rectangle/Rectangle.class
Normal file
BIN
DEV2.1/TP09/03_Rectangle/Rectangle.class
Normal file
Binary file not shown.
29
DEV2.1/TP09/03_Rectangle/Rectangle.java
Normal file
29
DEV2.1/TP09/03_Rectangle/Rectangle.java
Normal file
@@ -0,0 +1,29 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Rectangle extends JComponent {
|
||||
|
||||
private int departX;
|
||||
private int departY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
|
||||
public Rectangle(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