DEV1.1
DEV2.1
TP01
TP02
TP03
TP04
TP05
TP06
TP07
TP08
Attente.class
Attente.java
CercleMagenta.class
CercleMagenta.java
FenetreListener.class
FenetreListener.java
Fond$1.class
Fond$2.class
Fond$3.class
Fond.class
Fond.java
Sautoir.class
Sautoir.java
TP09
TP10
controle_machine_1
SAE11_2024
SCR
.gitignore
README.md
38 lines
1.3 KiB
Java
38 lines
1.3 KiB
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
|
|
public class Sautoir extends JComponent {
|
|
|
|
@Override
|
|
protected void paintComponent(Graphics pinceau) {
|
|
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
|
|
Graphics secondPinceau = pinceau.create();
|
|
// obligatoire : si le composant n'est pas censé être transparent
|
|
if (this.isOpaque()) {
|
|
// obligatoire : on repeint toute la surface avec la couleur de fond
|
|
secondPinceau.setColor(this.getBackground());
|
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
}
|
|
|
|
int[] coord_x = {0, this.getWidth(), 0, this.getWidth()};
|
|
int[] coord_y = {0, 0, this.getHeight(), this.getHeight()};
|
|
Polygon p = new Polygon(coord_x, coord_y, 4);
|
|
secondPinceau.setColor(Color.CYAN);
|
|
secondPinceau.fillPolygon(p);
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
JFrame fenetre = new JFrame();
|
|
GridLayout layout = new GridLayout(5, 5);
|
|
// on configure la fenetre
|
|
fenetre.setSize(250, 250);
|
|
fenetre.setLocation(0, 0);
|
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
fenetre.setLayout(layout);
|
|
for (int i = 0; i != 25; i++) {
|
|
fenetre.add(new Sautoir());
|
|
}
|
|
fenetre.setVisible(true);
|
|
}
|
|
} |