tp6
This commit is contained in:
Binary file not shown.
@@ -24,7 +24,7 @@ public class JGrilleDeJeu extends JComponent {
|
||||
this.controleur = new ControleurClavier();
|
||||
this.fenetre.addKeyListener(controleur);
|
||||
this.directionActuelle = "Right";
|
||||
this.intervalleTimer = 500;
|
||||
this.intervalleTimer = 150;
|
||||
|
||||
Random r = new Random();
|
||||
int coordXPomme = Math.abs(r.nextInt() % TAILLE_GRILLE);
|
||||
@@ -145,13 +145,6 @@ public class JGrilleDeJeu extends JComponent {
|
||||
}
|
||||
this.coordSnake.addFirst(aAjouter);
|
||||
this.coordSnake.addFirst(coordQueue);
|
||||
|
||||
if (this.intervalleTimer != 200) {
|
||||
this.intervalleTimer -= 50;
|
||||
this.timer.cancel();
|
||||
this.timer = new Timer();
|
||||
this.timer.scheduleAtFixedRate(new TacheTimer(this), 0, this.intervalleTimer);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
BIN
DEV3.2/TP06/01_Traces/Main.class
Normal file
BIN
DEV3.2/TP06/01_Traces/Main.class
Normal file
Binary file not shown.
16
DEV3.2/TP06/01_Traces/Main.java
Normal file
16
DEV3.2/TP06/01_Traces/Main.java
Normal file
@@ -0,0 +1,16 @@
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces();
|
||||
|
||||
for (Map.Entry<Thread, StackTraceElement[]> thread : threads.entrySet()) {
|
||||
System.out.println(thread.getKey().getName() + " :");
|
||||
for (StackTraceElement trace : thread.getValue()) {
|
||||
System.out.println(" " + trace.getClassName() + "." + trace.getMethodName() + "(" + trace.getFileName() + ":" + trace.getLineNumber() + ")");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV3.2/TP06/02_Couleurs/ControleurListe.class
Normal file
BIN
DEV3.2/TP06/02_Couleurs/ControleurListe.class
Normal file
Binary file not shown.
25
DEV3.2/TP06/02_Couleurs/ControleurListe.java
Normal file
25
DEV3.2/TP06/02_Couleurs/ControleurListe.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import javax.swing.event.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import javax.swing.*;
|
||||
import java.awt.Color;
|
||||
|
||||
public class ControleurListe implements ListSelectionListener {
|
||||
|
||||
private String actuel;
|
||||
private JPanel panneau;
|
||||
private Map dictCouleurs;
|
||||
private JList liste;
|
||||
|
||||
public ControleurListe(JPanel panneau, Map dictCouleurs, JList liste) {
|
||||
this.panneau = panneau;
|
||||
this.dictCouleurs = dictCouleurs;
|
||||
this.liste = liste;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
this.panneau.setBackground((Color) this.dictCouleurs.get(this.liste.getSelectedValue()));
|
||||
this.panneau.repaint();
|
||||
}
|
||||
}
|
||||
BIN
DEV3.2/TP06/02_Couleurs/Fenetre.class
Normal file
BIN
DEV3.2/TP06/02_Couleurs/Fenetre.class
Normal file
Binary file not shown.
26
DEV3.2/TP06/02_Couleurs/Fenetre.java
Normal file
26
DEV3.2/TP06/02_Couleurs/Fenetre.java
Normal file
@@ -0,0 +1,26 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
|
||||
public Fenetre() {
|
||||
this.setSize(300, 200);
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(1, 2));
|
||||
|
||||
LectureFichier donnees = new LectureFichier();
|
||||
Map<String, Color> dictCouleurs = donnees.getDictCouleurs();
|
||||
|
||||
JList<String> listeCouleurs = new JList<>(dictCouleurs.keySet().toArray(new String[2]));
|
||||
JPanel couleur = new JPanel();
|
||||
couleur.setBackground(Color.WHITE);
|
||||
JScrollPane scroll = new JScrollPane(listeCouleurs);
|
||||
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
this.add(scroll);
|
||||
this.add(couleur);
|
||||
listeCouleurs.addListSelectionListener(new ControleurListe(couleur, dictCouleurs, listeCouleurs));
|
||||
}
|
||||
}
|
||||
BIN
DEV3.2/TP06/02_Couleurs/LectureFichier.class
Normal file
BIN
DEV3.2/TP06/02_Couleurs/LectureFichier.class
Normal file
Binary file not shown.
48
DEV3.2/TP06/02_Couleurs/LectureFichier.java
Normal file
48
DEV3.2/TP06/02_Couleurs/LectureFichier.java
Normal file
@@ -0,0 +1,48 @@
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.awt.*;
|
||||
|
||||
public class LectureFichier {
|
||||
|
||||
private Map<String, Color> dictCouleurs;
|
||||
|
||||
public LectureFichier() {
|
||||
this.dictCouleurs = new HashMap<>();
|
||||
|
||||
try {
|
||||
BufferedReader lecture = new BufferedReader(new FileReader("rgb.txt"));
|
||||
|
||||
try {
|
||||
String ligne = lecture.readLine();
|
||||
while(ligne != null) {
|
||||
String r = ligne.substring(0, 3).trim();
|
||||
String g = ligne.substring(4, 7).trim();
|
||||
String b = ligne.substring(8, 11).trim();
|
||||
|
||||
String nomCouleur = ligne.substring(11).strip();
|
||||
|
||||
this.dictCouleurs.put(nomCouleur, new Color(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b)));
|
||||
|
||||
ligne = lecture.readLine();
|
||||
|
||||
|
||||
}
|
||||
} catch(IOException e) {
|
||||
System.err.println("Erreur de lecture dans rgb.txt !");
|
||||
}
|
||||
try {
|
||||
lecture.close();
|
||||
} catch(IOException e) {
|
||||
System.err.println("Erreur de fermeture de rgb.txt !");
|
||||
}
|
||||
} catch(FileNotFoundException e) {
|
||||
System.err.println("Erreur d'ouverture de rgb.txt !");
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Color> getDictCouleurs() {
|
||||
return this.dictCouleurs;
|
||||
}
|
||||
}
|
||||
BIN
DEV3.2/TP06/02_Couleurs/Main.class
Normal file
BIN
DEV3.2/TP06/02_Couleurs/Main.class
Normal file
Binary file not shown.
6
DEV3.2/TP06/02_Couleurs/Main.java
Normal file
6
DEV3.2/TP06/02_Couleurs/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
752
DEV3.2/TP06/02_Couleurs/rgb.txt
Normal file
752
DEV3.2/TP06/02_Couleurs/rgb.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user