Fin de tout

This commit is contained in:
Simoes Lukas
2025-03-17 10:11:05 +01:00
parent cf33623a5d
commit 6f2ea4a30a
30 changed files with 355 additions and 23 deletions

Binary file not shown.

View 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;
}
}

Binary file not shown.

View 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));
}
}

Binary file not shown.

Binary file not shown.

View 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;
}
}

Binary file not shown.

View 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) {
}
}

Binary file not shown.

View 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.

View 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);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB