This commit is contained in:
Simoes Lukas
2025-03-11 10:02:42 +01:00
parent 9441c8978a
commit 2a0aa37baa
47 changed files with 561 additions and 3 deletions

Binary file not shown.

View File

@@ -0,0 +1,21 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Acharnement extends WindowAdapter{
private int compteur;
public Acharnement() {
this.compteur = 0;
}
@Override
public void windowClosing(WindowEvent evenement) {
if (this.compteur == 2) {
System.exit(0);
}
else {
this.compteur++;
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,13 @@
import java.awt.*;
import javax.swing.*;
public class AcharnementMain {
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setSize(300, 200);
fenetre.setLocation(100, 100);
fenetre.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
fenetre.addWindowListener(new Acharnement());
fenetre.setVisible(true);
}
}

Binary file not shown.

View File

@@ -0,0 +1,44 @@
import java.util.Arrays;
public class Configuration {
private char[][] grille;
public Configuration() {
this.grille = new char[3][3];
for(char[] ligne : grille) {
Arrays.fill(ligne, ' ');
}
}
public boolean estLibre(int x, int y) {
return this.grille[x][y] == ' ';
}
public Configuration jouer(int joueur, int x, int y) {
Configuration nouvelleConfig = this;
if (joueur == 1) {
nouvelleConfig.grille[x][y] = 'X';
return nouvelleConfig;
}
nouvelleConfig.grille[x][y] = 'O';
return nouvelleConfig;
}
// Pas demandé
public char[][] getGrille() {
return this.grille;
}
// Pas demandé
public String toString() {
String resultat = "";
for (char[] ligne : this.grille) {
resultat += Arrays.toString(ligne);
}
return resultat;
}
}

Binary file not shown.

View File

@@ -0,0 +1,8 @@
public class ConfigurationTest {
public static void main(String[] args) {
Configuration nouveau = new Configuration();
System.out.println(nouveau.estLibre(0, 0)); // Affiche bien true car la grille est vide
nouveau.jouer(1, 0, 0); // On joue dans cette case
System.out.println(nouveau.estLibre(0, 0)); // Affiche bien false car on vient de placer un joueur dans cette case
}
}

Binary file not shown.

View File

@@ -0,0 +1,28 @@
import java.awt.*;
import javax.swing.*;
public class Declinaisons extends JComponent {
private Color couleurTriangle;
public Declinaisons(Color couleurTriangle) {
super();
this.couleurTriangle = couleurTriangle;
}
@Override
public 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(this.couleurTriangle);
System.out.println("Width : " + this.getWidth() + " Height : " + this.getHeight());
int[] coord_x = {this.getWidth()/4, this.getWidth()/4*3, this.getWidth()/2};
int[] coord_y = {this.getHeight()/2, this.getHeight()/3, this.getHeight()/5*4};
secondPinceau.fillPolygon(coord_x, coord_y, 3);
}
}

Binary file not shown.

View File

@@ -0,0 +1,22 @@
import java.awt.*;
import javax.swing.*;
public class DeclinaisonsMain {
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setSize(300, 300);
fenetre.setLocation(100, 100);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setLayout(new GridLayout(2, 2));
JPanel[] panneaux = {new JPanel(), new JPanel(), new JPanel(), new JPanel()};
Color[] couleursTriangles = {Color.MAGENTA, Color.YELLOW, Color.CYAN, Color.BLUE};
Color[] couleursFonds = {Color.CYAN, Color.PINK, Color.MAGENTA, Color.YELLOW};
for (int i = 0; i != 4; i++) {
panneaux[i].setBackground(couleursFonds[i]);
panneaux[i].setLayout(new BorderLayout());
panneaux[i].add(new Declinaisons(couleursTriangles[i]), BorderLayout.CENTER);
fenetre.add(panneaux[i]);
}
fenetre.setVisible(true);
}
}

Binary file not shown.

View File

@@ -0,0 +1,9 @@
import java.util.Arrays;
public class Duplication {
public static void main(String[] args) {
double[] tab = new double[10];
Arrays.fill(tab, 5.8);
System.out.println(Arrays.toString(tab));
}
}

Binary file not shown.

View 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);
}
}