Ajout
This commit is contained in:
BIN
BUT1/DEV2.1/TP6-Dessin/EXO1/Formes.class
Normal file
BIN
BUT1/DEV2.1/TP6-Dessin/EXO1/Formes.class
Normal file
Binary file not shown.
35
BUT1/DEV2.1/TP6-Dessin/EXO1/Formes.java
Normal file
35
BUT1/DEV2.1/TP6-Dessin/EXO1/Formes.java
Normal file
@@ -0,0 +1,35 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Formes extends JComponent {
|
||||
|
||||
private Image imageDeCercle;
|
||||
public Formes() {
|
||||
super();
|
||||
this.imageDeCercle = Toolkit.getDefaultToolkit().getImage("image.png");
|
||||
}
|
||||
// Méthode pour dessiner sur le composant
|
||||
@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());
|
||||
}
|
||||
|
||||
// Maintenant on dessine ce que l'on veut
|
||||
secondPinceau.setColor(new Color(127,0,255)); // couleur du violet claire
|
||||
secondPinceau.drawString(">o<", 20, 20);
|
||||
secondPinceau.setColor(new Color(0,0,255));
|
||||
secondPinceau.drawRect(20,35,50,50);
|
||||
secondPinceau.setColor(new Color(30,255,30));
|
||||
secondPinceau.fillArc(20, 95, 50, 50, 0, 360);
|
||||
if (imageDeCercle != null) {
|
||||
secondPinceau.drawImage(imageDeCercle, 20, 150, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
BUT1/DEV2.1/TP6-Dessin/EXO1/Test.class
Normal file
BIN
BUT1/DEV2.1/TP6-Dessin/EXO1/Test.class
Normal file
Binary file not shown.
23
BUT1/DEV2.1/TP6-Dessin/EXO1/Test.java
Normal file
23
BUT1/DEV2.1/TP6-Dessin/EXO1/Test.java
Normal file
@@ -0,0 +1,23 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
// Création de la fenêtre
|
||||
JFrame fenetre = new JFrame("Test du dessin");
|
||||
fenetre.setSize(500,500);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
// Création d'une instance de la classe Formes
|
||||
Formes formes = new Formes();
|
||||
|
||||
// Ajout du panel à la fenêtre
|
||||
fenetre.add(formes);
|
||||
|
||||
// Définition de la taille de la fenêtre
|
||||
fenetre.setSize(300, 200);
|
||||
|
||||
// Rendre la fenêtre visible
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
BIN
BUT1/DEV2.1/TP6-Dessin/EXO1/image.png
Normal file
BIN
BUT1/DEV2.1/TP6-Dessin/EXO1/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
BIN
BUT1/DEV2.1/TP6-Dessin/EXO2/Sablier.class
Normal file
BIN
BUT1/DEV2.1/TP6-Dessin/EXO2/Sablier.class
Normal file
Binary file not shown.
30
BUT1/DEV2.1/TP6-Dessin/EXO2/Sablier.java
Normal file
30
BUT1/DEV2.1/TP6-Dessin/EXO2/Sablier.java
Normal file
@@ -0,0 +1,30 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Sablier extends JComponent {
|
||||
|
||||
// Méthode pour dessiner sur le composant
|
||||
@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, 5, 5);
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
int[] xPoints = {j * (50 + 20),50 + j * (50 + 20),j * (50 + 20),-50 + j * (50 + 20)};
|
||||
int[] yPoints = {i * (50 + 20),50 + i * (50 + 20),2 * 50 + i * (50 + 20),50 + i * (50 + 20)};
|
||||
|
||||
secondPinceau.setColor(new Color(37, 253, 233));
|
||||
secondPinceau.fillPolygon(xPoints, yPoints, 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
BIN
BUT1/DEV2.1/TP6-Dessin/EXO2/Test.class
Normal file
BIN
BUT1/DEV2.1/TP6-Dessin/EXO2/Test.class
Normal file
Binary file not shown.
23
BUT1/DEV2.1/TP6-Dessin/EXO2/Test.java
Normal file
23
BUT1/DEV2.1/TP6-Dessin/EXO2/Test.java
Normal file
@@ -0,0 +1,23 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
// Création de la fenêtre
|
||||
JFrame fenetre = new JFrame("Test du dessin");
|
||||
fenetre.setSize(500,500);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
// Création d'une instance de la classe Sablier
|
||||
Sablier formes = new Sablier();
|
||||
|
||||
// Ajout du panel à la fenêtre
|
||||
fenetre.add(formes);
|
||||
|
||||
// Définition de la taille de la fenêtre
|
||||
fenetre.setSize(300, 200);
|
||||
|
||||
// Rendre la fenêtre visible
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user