Fin de tout
This commit is contained in:
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user