debut TP DEV Piles

This commit is contained in:
Alexis WAMSTER 2023-10-25 19:48:54 +02:00
parent cb643ad0c0
commit 35918919b1
16 changed files with 186 additions and 17 deletions

BIN
Anglish/MailInstruction.docx Executable file

Binary file not shown.

Binary file not shown.

View File

@ -4,19 +4,44 @@ import java.awt.event.*;
import java.util.*;
public class Action implements MouseListener{
public java.util.List<Parallelogramme> listeParallelogramme;
public ListeParallelogramme listeParallelogramme;
public Point origine;
public JFrame fenetre;
public Action(java.util.List<Parallelogramme> listeParallelogramme){
public Action(ListeParallelogramme listeParallelogramme, JPanel panel, JFrame fenetre){
this.listeParallelogramme = listeParallelogramme;
this.origine = panel.getLocationOnScreen();
this.fenetre = fenetre;
}
@Override
public void mouseClicked(MouseEvent e){
for (Parallelogramme parallelogramme : this.listeParallelogramme){
if (parallelogramme.forme.contains(e.getPoint())){
System.out.println("clic");
Point clic = e.getPoint();
int x = clic.x - this.origine.x;
int y = clic.y - this.origine.y;
Parallelogramme parallelogramme = this.listeParallelogramme.get(-1);
while ((parallelogramme = this.listeParallelogramme.next(parallelogramme)) != null){
int[] xPoints = parallelogramme.forme.xpoints;
System.out.print("x=[");
for (int px : xPoints){
System.out.print(px+",");
}
System.out.print("] ");
int[] yPoints = parallelogramme.forme.ypoints;
System.out.print("y=[");
for (int yx : yPoints){
System.out.print(yx+",");
}
System.out.print("] ");
System.out.println(" clic=" + x + "," + y);
if (parallelogramme.forme.contains(x, y)){
System.out.println(parallelogramme.luminance());
this.listeParallelogramme.delete(parallelogramme);
fenetre.repaint();
break;
}
}
System.out.println();
}
@Override

Binary file not shown.

View File

@ -4,9 +4,9 @@ import java.util.*;
public class Dessin extends JComponent {
public java.util.List<Parallelogramme> listeParallelogramme;
public ListeParallelogramme listeParallelogramme;
public Dessin(java.util.List<Parallelogramme> listeParallelogramme){
public Dessin(ListeParallelogramme listeParallelogramme){
this.listeParallelogramme = listeParallelogramme;
}
@ -17,7 +17,8 @@ public class Dessin extends JComponent {
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
for (Parallelogramme parallelogramme : this.listeParallelogramme){
Parallelogramme parallelogramme = this.listeParallelogramme.get(-1);
while ((parallelogramme = this.listeParallelogramme.next(parallelogramme)) != null){
secondPinceau.setColor(parallelogramme.couleur);
secondPinceau.fillPolygon(parallelogramme.forme);
secondPinceau.setColor(Color.BLACK);

Binary file not shown.

View File

@ -0,0 +1,48 @@
import java.util.*;
public class ListeParallelogramme{
public List<Parallelogramme> liste;
public ListeParallelogramme(){
liste = new ArrayList<>();
}
public void add(){
int taille = this.liste.size();
if (taille == 0){
this.liste.add(new Parallelogramme());
}
else{
Parallelogramme dernier = this.liste.get(this.liste.size()-1);
this.liste.add(new Parallelogramme(dernier));
}
}
public void delete(Parallelogramme parallelogramme){
Parallelogramme suppr = parallelogramme;
while((parallelogramme = this.next(parallelogramme)) != null){
parallelogramme.translationGauche();
}
this.liste.remove(suppr);
}
public int size(){
return this.liste.size();
}
public Parallelogramme get(int indice){
if (indice >= 0 && indice < this.liste.size()){
return this.liste.get(indice);
}
return null;
}
public Parallelogramme next(Parallelogramme parallelogramme){
int indice = this.liste.indexOf(parallelogramme);
if (indice+1 < this.liste.size()){
return this.liste.get(indice+1);
}
return null;
}
}

Binary file not shown.

View File

@ -9,20 +9,20 @@ public class Main{
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
java.util.List<Parallelogramme> listeParallelogramme = new ArrayList<>();
int i;
Parallelogramme suivant = new Parallelogramme();
for (i=0; i<10; i++){
listeParallelogramme.add(suivant);
suivant = new Parallelogramme(suivant);
ListeParallelogramme listeParallelogramme = new ListeParallelogramme();
for (int i=0; i<10; i++){
listeParallelogramme.add();
}
Action action = new Action(listeParallelogramme);
fenetre.addMouseListener(action);
Dessin lesDessins = new Dessin(listeParallelogramme);
fenetre.add(lesDessins);
fenetre.setVisible(true);
JPanel origine = new JPanel();
fenetre.add(origine);
Action action = new Action(listeParallelogramme, origine, fenetre);
fenetre.addMouseListener(action);
}
}

View File

@ -25,4 +25,15 @@ public class Parallelogramme{
this.forme.addPoint(gauche+Parallelogramme.marge+Parallelogramme.largeur+Parallelogramme.inclinaison, haut);
this.forme.addPoint(gauche+Parallelogramme.marge+Parallelogramme.inclinaison, haut);
}
public void translationGauche(){
int[] xPoints = this.forme.xpoints;
int nbPoint = this.forme.npoints;
for (int i = 0; i < nbPoint; i++) {
xPoints[i] -= (Parallelogramme.largeur + Parallelogramme.marge);
}
}
public int luminance(){
return 21*this.couleur.getRed() + 72*this.couleur.getGreen() + 7*this.couleur.getBlue();
}
}

Binary file not shown.

View File

@ -0,0 +1,43 @@
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class Q1Main{
public static void main(String[] args) {
ArrayDeque<Integer> liste = new ArrayDeque<>();
int i;
try{
for (i=0; i<args.length; i++){
if (args[i].equals("*") || args[i].equals("/") || args[i].equals("+") || args[i].equals("-")){
int a;
int b;
a = liste.pop();
b = liste.pop();
if(args[i].equals("*")){
liste.push(b*a);
}
if(args[i].equals("/")){
liste.push(b/a);
}
if(args[i].equals("+")){
liste.push(b+a);
}
if(args[i].equals("-")){
liste.push(b-a);
}
}
else{
liste.push(Integer.parseInt(args[i]));
}
}
System.out.println(liste.pop());
}
catch(NoSuchElementException e){
System.out.println("tu ecrit bien");
}
catch(NumberFormatException e){
System.out.println("arretes de mal executer le code");
}
}
}

View File

@ -0,0 +1,25 @@
public class Q2Liste implements Q2Pile <T>{
public
public Q2Liste(){
}
@Override
public void push(T valeur){
}
@Override
public T pop(){
}
@Override
public boolean isEmpty(){
}
public T
}

View File

@ -0,0 +1,11 @@
public class Q2Maillon <T>{
T valeur;
Q2Maillon <T> ancien;
public Q2Maillon(Q2Maillon <T> ancien, T valeur){
this.ancien = ancien;
this.valeur = valeur;
}
}

View File

@ -0,0 +1,5 @@
public interface Q2Pile {
<T> void push(T valeur);
boolean isEmpty(void);
<T> T pop(void);
}