Skip to content
Commits on Source (2)
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
/AubergeEspagnol/target/ /AubergeEspagnol/target/
/Calculatrice/target/ /Calculatrice/target/
/MaCalculatrice/target/ /MaCalculatrice/target/
/Calculette/target/
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>Calculette</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.calculette;
import javax.swing.JFrame;
/**
*
* @author stag
*/
public class Main {
public static void main(String[] args) {
JFrame calc = new ma_calculatrice.Calculette(72);
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
import javax.swing.JFrame;
/**
*
* @author stag
*/
public class Calculette extends JFrame {
public Calculette(int i) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
/**
*
* @author stag
*/
import java.awt.Color;
import java.awt.Font;
import javax.swing.JButton;
public class DigitButton extends JButton {
protected Font font;
public DigitButton(String text, Font font) {
super(text);
this.font = font;
setup();
}
private void setup() {
this.setFont(font);
setBackground(Color.WHITE);
setOpaque(true);
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
import java.awt.Font;
import java.awt.LayoutManager;
import javax.swing.JButton;
import javax.swing.JPanel;
/**
*
* @author stag
*/
public class DigitPanels {
private Font font;
public DigitPanels(LayoutManager layout, Font font) {
super(layout);
this.font = font;
setup();
}
private void setup() {
// Les textes des boutons côté chiffres
String[] digitNames = {
"7", "8", "9",
"4", "5", "6",
"1", "2", "3",
"0", ".", "="
};
// Créer et ajouter les boutons au container idoine
for (int i = 0; i < 12; i++) {
JButton jb = new DigitButton(digitNames[i], font);
add(jb);
}
}
private void add(JButton jb) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
/**
*
* @author stag
*/
class DigitsPanel {
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JButton;
/**
*
* @author stag
*/
public class OperationButton {
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
import java.awt.Font;
import java.awt.LayoutManager;
import javax.swing.JPanel;
/**
*
* @author stag
*/
public class OperationPanel {
private Font font;
public OperationPanel(LayoutManager layout, Font font) {
super(layout);
this.font = font;
setup();
}
private void setup() {
// Les textes des boutons côté opérations
String[] opNames = {
"CE", "C",
"+", "-",
"x", "/"
};
// Créer et ajouter les boutons au container idoine
for (int i = 0; i < 6; i++) {
if (i == 0) {
RedOperationButton jb = new RedOperationButton(opNames[i], font);
add(jb);
} else {
OperationButton jb = new OperationButton(opNames[i], font);
add(jb);
}
}
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
import java.awt.Color;
import java.awt.Font;
/**
*
* @author stag
*/
public class RedOperationButton {
public RedOperationButton(String text, Font font) {
super(text, font);
setup();
}
private void setup() {
setForeground(Color.RED);
}
private void setForeground(Color RED) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.border.CompoundBorder;
/**
*
* @author stag
*/
public class Screen {
private Font font;
public Screen(String text, int horizontalAlignment, Font font) {
super(text, horizontalAlignment);
this.font = font;
setup();
}
private void setup() {
setFont(font);
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.BLACK, 2),
BorderFactory.createEmptyBorder(5, 5, 5, 5)
));
}
private void setFont(Font font) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
private void setBorder(CompoundBorder createCompoundBorder) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ma_calculatrice;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author stag
*/
public class calculette {
// Le gestionnaire de placement global
setLayout(new BorderLayout(2, 2));
// Les containers pour les boutons
DigitsPanel digitsPanel = new DigitsPanel(new GridLayout(0, 3, 2, 2), font);
OperationPanel operationsPanel = new OperationPanel(new GridLayout(0, 2, 2, 2), font);
// Créer les contenus graphiques : JLabel et JButton
JLabel screen = new Screen("0", JLabel.RIGHT, font);
// Ajouter les contenus graphiques dans les containers
add(screen, BorderLayout.NORTH);
// Ajouter les container à la fenêtre
add(digitsPanel, BorderLayout.WEST);
add(operationsPanel, BorderLayout.EAST);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
pack();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>Formulaire</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.formulaire;
import java.util.Scanner;
/**
*
* @author stag
*/
public class Form {
private String nom;
private String prenom;
private int age;
private void saisie() {
Scanner scanner = new Scanner(System.in);
System.out.print("Entrez le nom : ");
this.nom = scanner.nextLine();
System.out.print("Entrez le prénom : ");
this.prenom = scanner.nextLine();
System.out.print("Entrez l'âge : ");
this.age = scanner.nextInt();
}
private void verifierChaine(String s, int longueurMin, int longueurMax)
throws MalformedStringException {
if (s == null || s.length() < longueurMin || s.length() > longueurMax) {
throw new MalformedStringException("La chaîne \"" + s + "\" doit faire entre " +
longueurMin + " et " + longueurMax + " caractères.");
}
}
private void verifierEntier(int n, int min, int max) throws InvalidValueException {
if (n < min || n > max) {
throw new InvalidValueException("La valeur " + n + " doit être entre " + min + " et " + max + ".");
}
}
private void verifierEntrees() throws MalformedStringException, InvalidValueException {
verifierChaine(this.nom, 3, Integer.MAX_VALUE);
verifierChaine(this.prenom, 2, Integer.MAX_VALUE);
verifierEntier(this.age, 18, 65);
}
public Form() throws MalformedStringException, InvalidValueException {
this.saisie();
this.verifierEntrees();
}
public String getNom() {
return this.nom;
}
public String getPrenom() {
return this.prenom;
}
public int getAge() {
return this.age;
}
}
class MalformedStringException extends Exception {
public MalformedStringException(String message) {
super(message);
}
}
class InvalidValueException extends Exception {
private String nom;
private String prenom;
private int age;
public InvalidValueException(String message) {
super(message);
}
public boolean saisie(String nom, String prenom, int age) {
this.nom = nom;
this.prenom = prenom;
this.age = age;
verifierEntrees();
return exceptions.isEmpty();
}
private void verifierChaine(String s, int longueurMin, int longueurMax)
throws MalformedStringException {
if (s == null || s.length() < longueurMin || s.length() > longueurMax) {
throw new MalformedStringException("La chaîne '" + s + "' doit faire entre " + longueurMin +
" et " + longueurMax + " caractères");
}
}
private void verifierEntier(int nb, int min, int max) throws InvalidValueException {
if (nb < min || nb > max) {
throw new InvalidValueException("La valeur '" + nb + "' doit être comprise entre " + min +
" et " + max);
}
}
private void verifierEntrees() {
exceptions.clear();
try {
verifierChaine(nom, 3, Integer.MAX_VALUE);
} catch (MalformedStringException e) {
exceptions.add(e);
}
try {
verifierChaine(prenom, 2, Integer.MAX_VALUE);
} catch (MalformedStringException e) {
exceptions.add(e);
}
try {
verifierEntier(age, 18, 65);
} catch (InvalidValueException e) {
exceptions.add(e);
}
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.formulaire;
/**
*
* @author stag
*/
class exceptions {
static boolean isEmpty() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
static void clear() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
static void add(MalformedStringException e) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
static void add(InvalidValueException e) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>PlayCard</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Main;
import com.mycompany.playcard.CarteAJouer;
import com.mycompany.playcard.Hauteur;
import com.mycompany.playcard.Symbole;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
* @author stag
*/
public class MainClass {
public static void main(String[] args) {
CarteAJouer valetPique = new CarteAJouer(Hauteur.VALET, Symbole.PIQUE);
// Rien n'empêche de faire ça, même si ça n'a pas de sens !
//CarteAJouer toto = new CarteAJouer(128, 212);
System.out.println("valetPique = " + valetPique);
Jeu52Cartes jeu = new Jeu52Cartes();
System.out.println("jeu = " + jeu);
List<CarteAJouer> toto = new ArrayList<>(jeu.getJeu());
Collections.shuffle(toto);
System.out.println("toto = " + toto);
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.playcard;
/**
*
* @author stag
*/
public class CarteAJouer implements Comparable<CarteAJouer> {
// Les constantes de classe
public static final boolean ROUGE = true;
public static final boolean NOIR = false;
// Les attributs d'instance
private final Hauteur hauteur;
private final Symbole symbole;
public CarteAJouer(Hauteur hauteur, Symbole symbole) {
this.hauteur = hauteur;
this.symbole = symbole;
}
CarteAJouer(int hauteur, int symbole) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
public boolean getColor() {
if (symbole == Symbole.CARREAU || symbole == Symbole.COEUR) {
return ROUGE;
} else {
return NOIR;
}
}
public Hauteur getHauteur() {
return hauteur;
}
public Symbole getSymbole() {
return symbole;
}
/**
* Comparaison "façon bridge" : la hauteur prime, la couleur ensuite.
*
* @param valeurAComparer la carte à comparer à la carte courante
* @return négatif si this inférieur à valeur à comparer, positif ou nul
*/
@Override
public int compareTo(CarteAJouer valeurAComparer) {
if (this.hauteur.ordinal() - valeurAComparer.hauteur.ordinal() != 0) {
return this.hauteur.ordinal() - valeurAComparer.hauteur.ordinal();
} else {
return this.symbole.ordinal() - valeurAComparer.symbole.ordinal();
}
}
@Override
public int hashCode() {
int hash = 7;
hash = 47 * hash + this.hauteur.ordinal();
hash = 47 * hash + this.symbole.ordinal();
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final CarteAJouer other = (CarteAJouer) obj;
return (this.hauteur == other.hauteur && this.symbole == other.symbole);
}
private String hauteurVersTexte() {
String texte = null;
switch (this.hauteur) {
case AS:
texte = "As";
break;
case DEUX:
texte = "Deux";
break;
case TROIS:
texte = "Trois";
break;
case QUATRE:
texte = "Quatre";
break;
case CINQ:
texte = "Cinq";
break;
case SIX:
texte = "Six";
break;
case SEPT:
texte = "Sept";
break;
case HUIT:
texte = "Huit";
break;
case NEUF:
texte = "Neuf";
break;
case DIX:
texte = "Dix";
break;
case VALET:
texte = "Valet";
break;
case DAME:
texte = "Dame";
break;
case ROI:
texte = "Roi";
}
return texte;
}
private String symboleVersTexte() {
String texte = null;
switch (symbole) {
case TREFLE:
texte = "trèfle";
break;
case CARREAU:
texte = "carreau";
break;
case COEUR:
texte = "coeur";
break;
case PIQUE:
texte = "pique";
}
return texte;
}
@Override
public String toString() {
return hauteurVersTexte() + " de " + symboleVersTexte();
}
}
\ No newline at end of file
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.playcard;
/**
*
* @author stag
*/
public enum Hauteur {
AS, DEUX, TROIS, QUATRE, CINQ, SIX, SEPT, HUIT, NEUF, DIX, VALET, DAME, ROI;
}
\ No newline at end of file
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.playcard;
/**
*
* @author stag
*/
public enum Symbole {
TREFLE, CARREAU, COEUR, PIQUE;
}
\ No newline at end of file