Fin de tout
This commit is contained in:
BIN
DEV2.1/TP09/05_Balle/Balle.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Balle.class
Normal file
Binary file not shown.
45
DEV2.1/TP09/05_Balle/Balle.java
Normal file
45
DEV2.1/TP09/05_Balle/Balle.java
Normal file
@@ -0,0 +1,45 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Balle extends JComponent {
|
||||
|
||||
private int posXImage;
|
||||
private int posYImage;
|
||||
private Graphics pinceau;
|
||||
|
||||
public Balle(int posXImage, int posYImage) {
|
||||
this.posXImage = posXImage;
|
||||
this.posYImage = posYImage;
|
||||
}
|
||||
|
||||
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.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
|
||||
Image img = Toolkit.getDefaultToolkit().getImage("terre.jpg");
|
||||
secondPinceau.drawImage(img, 0, 0, this);
|
||||
|
||||
Image balle = Toolkit.getDefaultToolkit().getImage("balle.png");
|
||||
secondPinceau.drawImage(balle, this.posXImage, this.posYImage, this);
|
||||
|
||||
this.pinceau = secondPinceau;
|
||||
}
|
||||
|
||||
public void clearComponent() {
|
||||
this.pinceau.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
public int getPosX() {
|
||||
return this.posXImage;
|
||||
}
|
||||
|
||||
public int getPosY() {
|
||||
return this.posYImage;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/Fenetre.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Fenetre.class
Normal file
Binary file not shown.
16
DEV2.1/TP09/05_Balle/Fenetre.java
Normal file
16
DEV2.1/TP09/05_Balle/Fenetre.java
Normal file
@@ -0,0 +1,16 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setLocation(100,100);
|
||||
this.setSize(394,594);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(1, 1));
|
||||
Balle balle = new Balle(50, 50);
|
||||
this.add(balle);
|
||||
GestionSouris gestionSouris = new GestionSouris();
|
||||
this.addMouseListener(gestionSouris);
|
||||
this.addMouseMotionListener(new GestionnaireMouvementImage(this, balle, balle.getPosX(), balle.getPosY(), gestionSouris));
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/Fond.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Fond.class
Normal file
Binary file not shown.
BIN
DEV2.1/TP09/05_Balle/GestionSouris.class
Normal file
BIN
DEV2.1/TP09/05_Balle/GestionSouris.class
Normal file
Binary file not shown.
43
DEV2.1/TP09/05_Balle/GestionSouris.java
Normal file
43
DEV2.1/TP09/05_Balle/GestionSouris.java
Normal file
@@ -0,0 +1,43 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GestionSouris implements MouseListener {
|
||||
|
||||
private int sourisX;
|
||||
private int sourisY;
|
||||
|
||||
|
||||
public void mouseClicked(MouseEvent evenement) {
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent evenement){
|
||||
this.sourisX = evenement.getX()-4;
|
||||
this.sourisY = evenement.getY()-26;
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public int getSourisX() {
|
||||
return this.sourisX;
|
||||
}
|
||||
|
||||
public int getSourisY() {
|
||||
return this.sourisY;
|
||||
}
|
||||
|
||||
public void setSourisX(int a) {
|
||||
this.sourisX = a;
|
||||
}
|
||||
|
||||
public void setSourisY(int b) {
|
||||
this.sourisY = b;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/GestionnaireMouvementImage.class
Normal file
BIN
DEV2.1/TP09/05_Balle/GestionnaireMouvementImage.class
Normal file
Binary file not shown.
45
DEV2.1/TP09/05_Balle/GestionnaireMouvementImage.java
Normal file
45
DEV2.1/TP09/05_Balle/GestionnaireMouvementImage.java
Normal file
@@ -0,0 +1,45 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class GestionnaireMouvementImage implements MouseMotionListener {
|
||||
|
||||
private Fenetre fenetre;
|
||||
private Balle balle;
|
||||
private int posX;
|
||||
private int posY;
|
||||
private GestionSouris gestionSouris;
|
||||
|
||||
public GestionnaireMouvementImage(Fenetre fenetre, Balle balle, int x, int y, GestionSouris gestionSouris) {
|
||||
this.fenetre = fenetre;
|
||||
this.balle = balle;
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.gestionSouris = gestionSouris;
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent evenement) {
|
||||
if (evenement.getX()-4 >= this.posX && evenement.getX()-4 <= this.posX+29 &&
|
||||
evenement.getY()-26 >= this.posY && evenement.getY()-26 <= this.posY+28) {
|
||||
System.out.println("I'm gonna fucking kill myself");
|
||||
this.fenetre.remove(balle);
|
||||
int diffX = (evenement.getX()-4) - this.gestionSouris.getSourisX();
|
||||
int diffY = (evenement.getY()-26) - this.gestionSouris.getSourisY();
|
||||
this.posX += diffX;
|
||||
this.posY += diffY;
|
||||
|
||||
this.gestionSouris.setSourisX(evenement.getX()-4);
|
||||
this.gestionSouris.setSourisY(evenement.getY()-26);
|
||||
Balle balle = new Balle(this.posX, this.posY);
|
||||
this.balle = balle;
|
||||
this.fenetre.add(balle);
|
||||
this.fenetre.revalidate();
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent evenement) {
|
||||
|
||||
}
|
||||
}
|
||||
|
BIN
DEV2.1/TP09/05_Balle/Main.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Main.class
Normal file
Binary file not shown.
6
DEV2.1/TP09/05_Balle/Main.java
Normal file
6
DEV2.1/TP09/05_Balle/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/05_Balle/Rect.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Rect.class
Normal file
Binary file not shown.
29
DEV2.1/TP09/05_Balle/Rect.java
Normal file
29
DEV2.1/TP09/05_Balle/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);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/balle.png
Normal file
BIN
DEV2.1/TP09/05_Balle/balle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
DEV2.1/TP09/05_Balle/terre.jpg
Normal file
BIN
DEV2.1/TP09/05_Balle/terre.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
Reference in New Issue
Block a user