This commit is contained in:
Moncef STITI 2024-03-05 12:52:55 +01:00
parent c367c35d94
commit 77aea5b825
18 changed files with 365 additions and 14 deletions

View File

@ -1,16 +1,56 @@
public class PaperEnCm extends Paper { import java.awt.print.Paper;
// Attributs // Fait par Marco
private double Width_A4 = 8.27; // taille d'un pouce en cm -> 2.54
private double Height_A4 = 11.69; // 1/72 pouces -> 0.352778
private double Margin = 0.590551; // 1.5 cm to inches
// Constructeur public class Metrique extends Paper{
public PaperEnCm() {
Paper papier = new Paper(); public Metrique(){
setSize(Width_A4, Height_A4); this.setSize(8.26772,11.69291);
setImageableArea(Margin, Margin,Width_A4,Height_A4); this.setImageableArea(0.590551,0.590551,7.08661,10.51181);
} }
public double getMetric() public double getMetricHeight(){ // inch = 1/72 pouces
} return 0.352778*this.getHeight();
}
public double getMetricImageableHeight(){
return 2.54*this.getImageableHeight();
}
public double getMetricImageableWidth(){
return 2.54*this.getImageableWidth();
}
public double getMetricImageableX(){
return 2.54*this.getImageableX();
}
public double getMetricImageableY(){
return 2.54*this.getImageableY();
}
public double getMetricWidth(){
return 2.54*this.getWidth();
}
public void setMetricImageableArea(double x, double y, double width, double height){
setImageableArea(x/2.54, y/2.54, width/2.54, height/2.54);
return;
}
public void setMetricSize(double width, double height){
setSize(width/2.54, height/2.54);
}
public static void main(String[] args){
Metrique imprimante = new Metrique();
System.out.println(imprimante.getMetricImageableWidth());
System.out.println(imprimante.getMetricImageableX());
System.out.println(imprimante.getMetricImageableY());
System.out.println(imprimante.getMetricWidth());
// ...
return;
}
}

View File

@ -11,8 +11,6 @@ public class Nuancier{
System.out.println(element.decode()); System.out.println(element.decode());
} }
fenetre.add(panneau); fenetre.add(panneau);
fenetre.pack(); fenetre.pack();
fenetre.setVisible(true); fenetre.setVisible(true);

Binary file not shown.

View File

@ -0,0 +1,35 @@
import javax.swing.*;
import java.awt.*;
public class Formes extends JComponent {
private Image imageDeCercle;
public Formes() {
super();
this.imageDeCercle = Toolkit.getDefaultToolkit().getImage("image.png");
}
// Méthode pour dessiner sur le composant
@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());
}
// Maintenant on dessine ce que l'on veut
secondPinceau.setColor(new Color(127,0,255)); // couleur du violet claire
secondPinceau.drawString(">o<", 20, 20);
secondPinceau.setColor(new Color(0,0,255));
secondPinceau.drawRect(20,35,50,50);
secondPinceau.setColor(new Color(30,255,30));
secondPinceau.fillArc(20, 95, 50, 50, 0, 360);
if (imageDeCercle != null) {
secondPinceau.drawImage(imageDeCercle, 20, 150, this);
}
}
}

Binary file not shown.

View File

@ -0,0 +1,23 @@
import javax.swing.*;
import java.awt.*;
public class Test {
public static void main(String[] args) {
// Création de la fenêtre
JFrame fenetre = new JFrame("Test du dessin");
fenetre.setSize(500,500);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Création d'une instance de la classe Formes
Formes formes = new Formes();
// Ajout du panel à la fenêtre
fenetre.add(formes);
// Définition de la taille de la fenêtre
fenetre.setSize(300, 200);
// Rendre la fenêtre visible
fenetre.setVisible(true);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

View File

@ -0,0 +1,30 @@
import javax.swing.*;
import java.awt.*;
public class Sablier extends JComponent {
// Méthode pour dessiner sur le composant
@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, 5, 5);
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
int[] xPoints = {j * (50 + 20),50 + j * (50 + 20),j * (50 + 20),-50 + j * (50 + 20)};
int[] yPoints = {i * (50 + 20),50 + i * (50 + 20),2 * 50 + i * (50 + 20),50 + i * (50 + 20)};
secondPinceau.setColor(new Color(37, 253, 233));
secondPinceau.fillPolygon(xPoints, yPoints, 4);
}
}
}
}

Binary file not shown.

View File

@ -0,0 +1,23 @@
import javax.swing.*;
import java.awt.*;
public class Test {
public static void main(String[] args) {
// Création de la fenêtre
JFrame fenetre = new JFrame("Test du dessin");
fenetre.setSize(500,500);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Création d'une instance de la classe Sablier
Sablier formes = new Sablier();
// Ajout du panel à la fenêtre
fenetre.add(formes);
// Définition de la taille de la fenêtre
fenetre.setSize(300, 200);
// Rendre la fenêtre visible
fenetre.setVisible(true);
}
}

View File

@ -0,0 +1,19 @@
public class Moto implements Vehicule {
private String sorte;
private int nbRoues;
public Moto() {
sorte = "Moto";
nbRoues = 2;
}
@Override
public int nbRoues() {
return nbRoues;
}
@Override
public String sorte() {
return sorte;
}
}

View File

@ -0,0 +1,22 @@
import javax.swing.JOptionPane;
public class Test {
public static void main(String[] args) {
Vehicule v;
Object[] choix = {"Voiture", "Moto"};
int reponse = JOptionPane.showOptionDialog(null,
"Quel v\u00E9hicule choisissez-vous ?",
"Question",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
choix,
null);
if (reponse == 0)
v = new Voiture();
else
v = new Moto();
System.out.println("Une "+v.sorte()+" poss\u00E8de "+v.nbRoues()+" roues.");
}
}

View File

@ -0,0 +1,4 @@
public interface Vehicule{
int nbRoues();
String sorte();
}

View File

@ -0,0 +1,19 @@
public class Voiture implements Vehicule {
private String sorte;
private int nbRoues;
public Voiture() {
sorte = "Voiture";
nbRoues = 4;
}
@Override
public int nbRoues() {
return nbRoues;
}
@Override
public String sorte() {
return sorte;
}
}

View File

@ -0,0 +1,53 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Fond implements ActionListener {
static JPanel panneau;
static ActionListener unObservateur1 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(new Color(0, 255, 255)); // Rouge
}
};
static ActionListener unObservateur2 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(new Color(255, 0, 255)); // Vert
}
};
static ActionListener unObservateur3 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(new Color(255, 255, 0)); // Bleu
}
};
public static void main(String[] args) {
JFrame fenetre = new JFrame("Fond");
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setSize(500, 500);
panneau = new JPanel();
JButton cyan = new JButton("Cyan");
JButton magenta = new JButton("Magenta");
JButton jaune = new JButton("Jaune");
panneau.add(cyan);
cyan.addActionListener(unObservateur1);
panneau.add(magenta);
magenta.addActionListener(unObservateur2);
panneau.add(jaune);
jaune.addActionListener(unObservateur3);
fenetre.add(panneau);
fenetre.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// Vous pouvez implémenter cette méthode si nécessaire
}
}

View File

@ -0,0 +1,28 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Fond Attente ActionListener {
static JPanel panneau;
public static void main(String[] args) {
JFrame fenetre = new JFrame("Fond");
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setSize(500, 500);
JPanel panneau = new JPanel();
fenetre.add(panneau);
fenetre.setVisible(true);
}
}
try {
int n = Integer.parseInt(args[0]);
System.out.println("En hexadecimal" + Integer.toHexString(n));
}catch(NumberFormatException e){
System.err.println("Ceci n'est pas un" + "entier !");
} catch(ArrayIndexOutOfBoundsException e){
System.err.println("Il faut un argument :");
}

View File

@ -0,0 +1,57 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Radio implements ActionListener {
static JPanel panneau;
static ActionListener unObservateur1 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(new Color(0, 255, 255)); // Rouge
}
};
static ActionListener unObservateur2 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(new Color(255, 0, 255)); // Vert
}
};
static ActionListener unObservateur3 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(new Color(255, 255, 0)); // Bleu
}
};
public static void main(String[] args) {
JFrame fenetre = new JFrame("Fond version radio bouton");
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setSize(500, 500);
panneau = new JPanel();
JRadioButton cyan = new JRadioButton("Cyan");
JRadioButton magenta = new JRadioButton("Magenta");
JRadioButton jaune = new JRadioButton("Jaune");
ButtonGroup groupe = new ButtonGroup();
groupe.add(cyan);
groupe.add(magenta);
groupe.add(jaune);
panneau.add(cyan);
cyan.addActionListener(unObservateur1);
panneau.add(magenta);
magenta.addActionListener(unObservateur2);
panneau.add(jaune);
jaune.addActionListener(unObservateur3);
fenetre.add(panneau);
fenetre.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// Vous pouvez implémenter cette méthode si nécessaire
}
}