Ajout
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
Main.java, SkyFrame.java et SunPanel.java on été générer par ChatGPT.
|
||||
|
||||
Le code n'est pas forcément bon, c'est juste pour voir comment faire
|
@@ -0,0 +1,12 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
SkyFrame skyFrame = new SkyFrame();
|
||||
skyFrame.setSize(800, 600);
|
||||
skyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
skyFrame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class SkyFrame extends JFrame {
|
||||
private SunPanel sunPanel;
|
||||
|
||||
public SkyFrame() {
|
||||
setTitle("Sky with Sun");
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
sunPanel = new SunPanel();
|
||||
add(sunPanel, BorderLayout.CENTER);
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
sunPanel.increaseSunRadius(15);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user