commit e425718364bbb764518b70879212b7edba175dfd Author: martins Date: Wed Apr 20 00:33:31 2022 +0200 test de départ ( essaie selection ligne, collonne et mines) diff --git a/main_ex.class b/main_ex.class new file mode 100644 index 0000000..892d803 Binary files /dev/null and b/main_ex.class differ diff --git a/main_ex.java b/main_ex.java new file mode 100644 index 0000000..9b43fd1 --- /dev/null +++ b/main_ex.java @@ -0,0 +1,42 @@ +// Tom Monint et Clément Martins +// main_ex V1 +// Classe ayant pour but d'être executer + +//importons les packages necessaires +import java.awt.*; +import javax.swing.*; + +public class main_ex{ + public static void main(String[] args){ + // on initialise une fenettre + JFrame fenetre = new JFrame("Démineur"); + fenetre.setLocation(0,0); + //on choisi une taille arbitraire + fenetre.setSize(1000,800); + //nous utiliserons un gestionnaire GridLayout + GridLayout grille = new GridLayout(1, 3); + fenetre.setLayout(grille); + // l'application ne se fermera que si on clique sur + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + fenetre.setVisible(true); + + main_ex.affichageChoixTaille(fenetre); + } + private static int[] affichageChoixTaille(JFrame fenetre){ + // fonction pour la selection des lignes et des collones de l'aplication + paintChoix moins = new paintChoix(1); + paintChoix plus = new paintChoix(2); + nombre compte = new nombre(); + JLabel neutre = new JLabel(compte.toString()); + JPanel panneau = new JPanel(); + observateurChoix ob1 = new observateurChoix(-1, moins, compte); + moins.addMouseListener(ob1); + observateurChoix ob2 = new observateurChoix(1, plus, compte); + plus.addMouseListener(ob2); + + fenetre.add(moins); + fenetre.add(neutre); + fenetre.add(plus); + return (new int[3]); + } +} \ No newline at end of file diff --git a/nombre.class b/nombre.class new file mode 100644 index 0000000..84b98b4 Binary files /dev/null and b/nombre.class differ diff --git a/nombre.java b/nombre.java new file mode 100644 index 0000000..74f014d --- /dev/null +++ b/nombre.java @@ -0,0 +1,23 @@ +public class nombre{ + private int nombre; + private int max; + public nombre(){ + this.nombre=4; + // il y a au minimun 4 ligne et 4 collonnes + this.max=30; + // il y a 30 ligne et collonne au max + } + public void addNombre(int n){ + this.nombre+=n; + if(this.nombre<4){ + this.nombre=4; + } + if(this.nombre>this.max){ + this.nombre=this.max; + } + } + @Override + public String toString(){ + return String.valueOf(this.nombre); + } +} \ No newline at end of file diff --git a/observateurChoix.class b/observateurChoix.class new file mode 100644 index 0000000..f1523bc Binary files /dev/null and b/observateurChoix.class differ diff --git a/observateurChoix.java b/observateurChoix.java new file mode 100644 index 0000000..72bbea4 --- /dev/null +++ b/observateurChoix.java @@ -0,0 +1,43 @@ +//Tom Monin et Clément Martins +// observateurChoix V1 +//Class pour la selection du nombre de collone et ligne et de Mine a la souris +import java.awt.*; +import java.awt.event.*; + +public class observateurChoix implements MouseListener{ + private int direction; + private paintChoix pinceau; + private nombre compte; + public observateurChoix(int direction0, paintChoix pinceau0, nombre compte0){ + this.direction=direction0; + // pour savoir si c'est l'observateur de la fleche de gauche ou droite + this.pinceau=pinceau0; + this.compte=compte0; + } + @Override + public void mouseClicked(MouseEvent evenement){ + compte.addNombre(direction); + + } + @Override // un bouton cliqué + public void mouseEntered(MouseEvent evenement){ + pinceau.selectionner(true); + pinceau.repaint(); + + } + @Override // debut du survol + public void mouseExited(MouseEvent evenement){ + pinceau.selectionner(false); + pinceau.repaint(); + + } + @Override // fin du survol + public void mousePressed(MouseEvent evenement){ + + } + @Override // un bouton appuyé + public void mouseReleased(MouseEvent evenement){ + + } + +} \ No newline at end of file diff --git a/paintChoix.class b/paintChoix.class new file mode 100644 index 0000000..5384868 Binary files /dev/null and b/paintChoix.class differ diff --git a/paintChoix.java b/paintChoix.java new file mode 100644 index 0000000..2e3797f --- /dev/null +++ b/paintChoix.java @@ -0,0 +1,67 @@ +// Tom Monin et Clément Martins +// paintChoix V1 +// class pour l'affichage de la selection des lignes, collonnes et nombre de mines + +import java.awt.*; +import javax.swing.*; +import javax.swing.JComponent; + +public class paintChoix extends JComponent{ + private boolean selectionner; + private int direction; + + public paintChoix(int direction0){ + + this.selectionner=false; + //de base ce n'est pas selectionner + this.direction=direction0; + //initialser arbitrairement sur 0 + } + public void selectionner(boolean verif){ + this.selectionner=verif; + } + @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()); + } + if(selectionner==true){ + secondPinceau.setColor(new Color(0,255,255)); + secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); + }else{ + secondPinceau.setColor(new Color(215,215,215)); + secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + if(this.direction==1){ + secondPinceau.setColor(new Color(0,0,0)); + secondPinceau.fillRect(this.getWidth()/5, this.getHeight()/3, this.getWidth()/5*4, this.getHeight()/3); + int[] x= new int[3]; + int[] y= new int[3]; + x[0]=this.getWidth()/5; + x[1]=0; + x[2]=x[0]; + y[0]=0; + y[1]=this.getHeight()/2; + y[2]=this.getHeight(); + secondPinceau.fillPolygon(x, y, 3); + } + if(this.direction==2){ + secondPinceau.setColor(new Color(0,0,0)); + secondPinceau.fillRect(0, this.getHeight()/3, this.getWidth()/5*4, this.getHeight()/3); + int[] x= new int[3]; + int[] y= new int[3]; + x[0]=this.getWidth()/5*4; + x[1]=this.getWidth(); + x[2]=x[0]; + y[0]=0; + y[1]=this.getHeight()/2; + y[2]=this.getHeight(); + secondPinceau.fillPolygon(x, y, 3); + } + } +} \ No newline at end of file diff --git a/test.class b/test.class new file mode 100644 index 0000000..aa6eb49 Binary files /dev/null and b/test.class differ diff --git a/test.java b/test.java new file mode 100644 index 0000000..5d56768 --- /dev/null +++ b/test.java @@ -0,0 +1,36 @@ +// Tom Monint et Clément Martins +// main_ex V1 +// Classe ayant pour but d'être executer + +//importons les packages necessaires +import java.awt.*; +import javax.swing.*; + +public class test{ + public static void main(String[] args){ + // on initialise une fenettre + JFrame fenetre = new JFrame("Démineur"); + fenetre.setLocation(0,0); + //on choisi une taille arbitraire + fenetre.setSize(1000,800); + //nous utiliserons un gestionnaire GridLayout + fenetre.setLayout(null); + // l'application ne se fermera que si on clique sur + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + fenetre.setVisible(true); + + test.affichageChoixTaille(fenetre); + } + private static int[] affichageChoixTaille(JFrame fenetre){ + // fonction pour la selection des lignes et des collones de l'aplication + paintChoix pinceauMoins = new paintChoix(1); + paintChoix pinceauPlus = new paintChoix(2); + pinceauMoins.setSize(fenetre.getWidth()/10, fenetre.getHeight()/10); + pinceauMoins.setLocation(fenetre.getWidth()/5, fenetre.getHeight()/2); + pinceauPlus.setSize(fenetre.getWidth()/10, fenetre.getHeight()/10); + pinceauPlus.setLocation(fenetre.getWidth()/5*3, fenetre.getHeight()/2); + fenetre.add(pinceauMoins); + fenetre.add(pinceauPlus); + return (new int[3]); + } +} \ No newline at end of file