TP06
This commit is contained in:
BIN
DEV2.1/TP06/Formes.class
Normal file
BIN
DEV2.1/TP06/Formes.class
Normal file
Binary file not shown.
47
DEV2.1/TP06/Formes.java
Normal file
47
DEV2.1/TP06/Formes.java
Normal file
@@ -0,0 +1,47 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Formes extends JComponent {
|
||||
|
||||
private String typeComposant;
|
||||
|
||||
public Formes(String typeComposant) {
|
||||
super();
|
||||
this.typeComposant = typeComposant;
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
if (this.typeComposant == "Carre") {
|
||||
secondPinceau.setColor(new Color(51,153,255));
|
||||
secondPinceau.fillRect(0, 0, 50, 50);
|
||||
secondPinceau.setColor(Color.BLUE);
|
||||
secondPinceau.drawRect(0,0,50,50);
|
||||
}
|
||||
|
||||
if (this.typeComposant == "Disque") {
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame fenetre = new JFrame();
|
||||
Formes test = new Formes("Carre");
|
||||
// on configure la fenetre
|
||||
fenetre.setSize(500, 500);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.add(test);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user