DEV_BUT1/DEV2.1/TP06/Exo1/Carre.java

27 lines
764 B
Java
Raw Normal View History

2023-04-04 14:03:16 +02:00
import javax.swing.*;
import java.awt.*;
public class Carre extends JComponent{
private Image pingouin;
public Carre(){
super();
this.pingouin = Toolkit.getDefaultToolkit().getImage("cercles.png");
}
@Override
protected void paintComponent(Graphics pinceau){
Graphics secondPinceau = pinceau.create();
if (this.isOpaque()){
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
secondPinceau.setColor(Color.BLUE);
secondPinceau.drawRect(150,200,50,50);
secondPinceau.setColor(Color.GREEN);
secondPinceau.drawOval(100,100,25,25);
secondPinceau.drawImage(this.pingouin, 150, 125, this);
secondPinceau.drawString("Bonjour !", 300, 180);
}
}