TP
This commit is contained in:
BIN
DEV2.1/controle_machine_1/Acharnement.class
Normal file
BIN
DEV2.1/controle_machine_1/Acharnement.class
Normal file
Binary file not shown.
21
DEV2.1/controle_machine_1/Acharnement.java
Normal file
21
DEV2.1/controle_machine_1/Acharnement.java
Normal 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++;
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/controle_machine_1/AcharnementMain.class
Normal file
BIN
DEV2.1/controle_machine_1/AcharnementMain.class
Normal file
Binary file not shown.
13
DEV2.1/controle_machine_1/AcharnementMain.java
Normal file
13
DEV2.1/controle_machine_1/AcharnementMain.java
Normal 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);
|
||||
}
|
||||
}
|
BIN
DEV2.1/controle_machine_1/Configuration.class
Normal file
BIN
DEV2.1/controle_machine_1/Configuration.class
Normal file
Binary file not shown.
44
DEV2.1/controle_machine_1/Configuration.java
Normal file
44
DEV2.1/controle_machine_1/Configuration.java
Normal 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;
|
||||
}
|
||||
}
|
BIN
DEV2.1/controle_machine_1/ConfigurationTest.class
Normal file
BIN
DEV2.1/controle_machine_1/ConfigurationTest.class
Normal file
Binary file not shown.
8
DEV2.1/controle_machine_1/ConfigurationTest.java
Normal file
8
DEV2.1/controle_machine_1/ConfigurationTest.java
Normal 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
|
||||
}
|
||||
}
|
BIN
DEV2.1/controle_machine_1/Declinaisons.class
Normal file
BIN
DEV2.1/controle_machine_1/Declinaisons.class
Normal file
Binary file not shown.
28
DEV2.1/controle_machine_1/Declinaisons.java
Normal file
28
DEV2.1/controle_machine_1/Declinaisons.java
Normal 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);
|
||||
}
|
||||
}
|
BIN
DEV2.1/controle_machine_1/DeclinaisonsMain.class
Normal file
BIN
DEV2.1/controle_machine_1/DeclinaisonsMain.class
Normal file
Binary file not shown.
22
DEV2.1/controle_machine_1/DeclinaisonsMain.java
Normal file
22
DEV2.1/controle_machine_1/DeclinaisonsMain.java
Normal 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);
|
||||
}
|
||||
}
|
BIN
DEV2.1/controle_machine_1/Duplication.class
Normal file
BIN
DEV2.1/controle_machine_1/Duplication.class
Normal file
Binary file not shown.
9
DEV2.1/controle_machine_1/Duplication.java
Normal file
9
DEV2.1/controle_machine_1/Duplication.java
Normal 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));
|
||||
}
|
||||
}
|
BIN
DEV2.1/controle_machine_1/Sautoir.class
Normal file
BIN
DEV2.1/controle_machine_1/Sautoir.class
Normal file
Binary file not shown.
38
DEV2.1/controle_machine_1/Sautoir.java
Normal file
38
DEV2.1/controle_machine_1/Sautoir.java
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user