TP
This commit is contained in:
38
DEV2.1/controle_machine_1/Sautoir.java
Normal file
38
DEV2.1/controle_machine_1/Sautoir.java
Normal file
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user