DEV/BUT1/CONTROLE/DEV2.1/Entrainement/SUJETB/EXO4/SolutiondeGPT/SunPanel.java
2024-03-09 16:05:37 +01:00

39 lines
1.0 KiB
Java

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class SunPanel extends JPanel {
private int sunRadius;
public SunPanel() {
sunRadius = 50; // Rayon initial du soleil
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
increaseSunRadius(15);
}
});
}
public void increaseSunRadius(int increment) {
sunRadius += increment;
repaint();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(new Color(115, 194, 251)); // Couleur du ciel
g2d.fillRect(0, 0, getWidth(), getHeight());
int sunX = getWidth() / 2 - sunRadius;
int sunY = getHeight() - sunRadius * 2;
g2d.setColor(Color.YELLOW); // Couleur du soleil
g2d.fillOval(sunX, sunY, sunRadius * 2, sunRadius * 2);
}
}