Controle machine

This commit is contained in:
Simoes Lukas
2025-03-19 10:18:41 +01:00
parent 42cc204dea
commit 376861b608
86 changed files with 803 additions and 179 deletions

View File

@@ -1,21 +0,0 @@
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++;
}
}
}

View File

@@ -1,13 +0,0 @@
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);
}
}

View File

@@ -0,0 +1,13 @@
import java.awt.*;
public class Filtre {
public static String minusculesDansChaine(String chaine) {
String chaineFinale = "";
for (int i = 0; i != chaine.length(); i++) {
if(Character.isLowerCase(chaine.charAt(i))) {
chaineFinale += chaine.charAt(i);
}
}
return chaineFinale;
}
}

View File

@@ -0,0 +1,14 @@
public class Main {
public static void main(String[] args) {
// Tests de la méthode
/* String texte = "CeCi eSt uN TesT";
String texte2 = "mMiAnJuUsScCuUlLeEsS ";
System.out.println(Filtre.minusculesDansChaine(texte));
System.out.println(Filtre.minusculesDansChaine(texte2)); */
for (String chaine : args) {
System.out.println(Filtre.minusculesDansChaine(chaine));
}
}
}

View File

@@ -0,0 +1,16 @@
import java.awt.*;
import java.util.Random;
public class Exquis {
private String[] chaines;
public Exquis(String[] chaines) {
this.chaines = chaines;
}
public String toString() {
Random aleatoire = new Random();
return this.chaines[Math.abs(aleatoire.nextInt()) % this.chaines.length];
}
}

View File

@@ -0,0 +1,35 @@
public class Main {
public static void main(String[] args) {
String[] sujets = {
"Luc",
"Denis",
"Régine",
"Selma",
"Frédéric"
};
String[] verbes = {
"aime",
"déteste",
"tue",
"mange",
"épouse"
};
String[] complements = {
"Windows",
"les pommes",
"Elizabeth II",
"les batyscaphes" // Je sais même pas si c'est un nom commun en vrai
};
Exquis sujet = new Exquis(sujets);
Exquis verbe = new Exquis(verbes);
Exquis complement = new Exquis(complements);
for (int i = 0; i != 5; i++) {
System.out.println(sujet + " " + verbe + " " + complement);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,31 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(250, 300);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
JPanel panneauHaut = new JPanel();
JPanel panneauBas = new JPanel();
JPanel panneauMilieu = new JPanel();
JButton boutonHaut = new JButton("\u25B2");
JButton boutonBas = new JButton("\u25BC");
Six imageSix = new Six();
boutonHaut.setHorizontalAlignment(JButton.CENTER);
boutonBas.setHorizontalAlignment(JButton.CENTER);
panneauHaut.add(boutonHaut);
panneauBas.add(boutonBas);
panneauMilieu.add(imageSix);
this.add(panneauHaut, BorderLayout.NORTH);
this.add(panneauBas, BorderLayout.SOUTH);
this.add(imageSix, BorderLayout.CENTER);
}
}

View File

@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
Fenetre fenetre = new Fenetre();
fenetre.setVisible(true);
}
}

View File

@@ -0,0 +1,19 @@
import java.awt.*;
import javax.swing.*;
public class Six extends JComponent {
@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());
}
Image img = Toolkit.getDefaultToolkit().getImage("6.png");
// On place l'image au milieu de son composant puis on soustrait par la moitié des dimensions de l'image (55x80)
secondPinceau.drawImage(img, this.getWidth()/2 - 27 , this.getHeight()/2 - 40, this);
}
}

View File

@@ -0,0 +1,19 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(300, 400);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(1, 1));
JPanel fond = new JPanel();
fond.setBackground(Color.BLACK);
this.add(fond);
GestionMolette molette = new GestionMolette(fond);
this.addMouseWheelListener(molette);
}
}

View File

@@ -0,0 +1,21 @@
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class GestionMolette implements MouseWheelListener {
private JPanel fond;
public GestionMolette(JPanel fond) {
this.fond = fond;
}
public void mouseWheelMoved(MouseWheelEvent evenement) {
if (evenement.getWheelRotation() < 0) {
this.fond.setBackground(Color.WHITE);
}
else {
this.fond.setBackground(Color.BLACK);
}
}
}

View File

@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
Fenetre fenetre = new Fenetre();
fenetre.setVisible(true);
}
}

View File

@@ -1,44 +0,0 @@
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;
}
}

View File

@@ -1,8 +0,0 @@
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
}
}

View File

@@ -1,28 +0,0 @@
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,24 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(400, 400);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(2, 2));
JPanel[] panneaux = new JPanel[4];
Color[] couleursFond = {Color.CYAN, Color.PINK, Color.MAGENTA, Color.YELLOW};
Color[] couleursTriangles = {Color.MAGENTA, Color.YELLOW, Color.CYAN, Color.BLUE};
for (int i = 0; i != 4; i++) {
panneaux[i] = new JPanel();
panneaux[i].setLayout(new BorderLayout());
panneaux[i].setOpaque(true);
panneaux[i].setBackground(couleursFond[i]);
panneaux[i].add(new Triangle(couleursTriangles[i]), BorderLayout.CENTER);
this.add(panneaux[i]);
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
Fenetre fenetre = new Fenetre();
fenetre.setVisible(true);
}
}

Binary file not shown.

View File

@@ -0,0 +1,27 @@
import java.awt.*;
import javax.swing.*;
public class Triangle extends JComponent {
private Color couleur;
public Triangle(Color couleur) {
super();
this.couleur = couleur;
}
@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.couleur);
int[] coordTriangleX = {0, this.getWidth(), this.getWidth()/2};
int[] coordTriangleY = {this.getHeight()/3, this.getHeight()/4*3, this.getHeight()};
secondPinceau.fillPolygon(coordTriangleX, coordTriangleY, 3);
}
}

View File

@@ -1,22 +0,0 @@
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);
}
}

View File

@@ -1,6 +1,7 @@
import java.awt.*;
import java.util.Arrays;
public class Duplication {
public class Main {
public static void main(String[] args) {
double[] tab = new double[10];
Arrays.fill(tab, 5.8);

Binary file not shown.

View File

@@ -0,0 +1,23 @@
import java.awt.*;
public class Configuration {
private String[][] grille;
public Configuration() {
String[][] temp = {
{" ", " ", " "},
{" ", " ", " "},
{" ", " ", " "}
};
this.grille = temp;
}
public boolean estLibre(int x, int y) {
return this.grille[x][y].equals(" ");
}
public void jouer(int x, int y, String joueur) {
this.grille[x][y] = joueur;
}
}

Binary file not shown.

View File

@@ -0,0 +1,8 @@
public class Main {
public static void main(String[] args) {
Configuration test = new Configuration();
System.out.println(test.estLibre(1, 1) + "");
test.jouer(1, 1, "X");
System.out.println(test.estLibre(1, 1) + "");
}
}

View File

@@ -1,38 +0,0 @@
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);
}
}