39 lines
924 B
Java
39 lines
924 B
Java
package linea;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Graphics;
|
|
import java.util.Random;
|
|
|
|
public class FondEspace extends ObjetGraphique {
|
|
private int[] starX = new int[100];
|
|
private int[] starY = new int[100];
|
|
private Random rand = new Random();
|
|
|
|
public FondEspace() {
|
|
for (int i = 0; i < 100; i++) {
|
|
starX[i] = rand.nextInt(800);
|
|
starY[i] = rand.nextInt(600);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
void Afficher(Graphics g) {
|
|
// Espace profond
|
|
g.setColor(Color.BLACK);
|
|
g.fillRect(0, 0, 800, 600);
|
|
|
|
// Étoiles
|
|
g.setColor(Color.WHITE);
|
|
for (int i = 0; i < 100; i++) {
|
|
g.fillOval(starX[i], starY[i], 2, 2);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
void Animer() {
|
|
for (int i = 0; i < 100; i++) {
|
|
starX[i] -= 2; // Défilement vers la gauche
|
|
if (starX[i] < 0) starX[i] = 800;
|
|
}
|
|
}
|
|
} |