TP
This commit is contained in:
BIN
DEV2.1/TP13/01_Devinette/Main.class
Normal file
BIN
DEV2.1/TP13/01_Devinette/Main.class
Normal file
Binary file not shown.
50
DEV2.1/TP13/01_Devinette/Main.java
Normal file
50
DEV2.1/TP13/01_Devinette/Main.java
Normal file
@@ -0,0 +1,50 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Random aleatoire = new Random();
|
||||
int aDeviner = aleatoire.nextInt(100) + 1;
|
||||
|
||||
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
|
||||
String essai = "-1";
|
||||
|
||||
try {
|
||||
System.out.println("Essai n°1 : Veuillez entrer un nombre (1 à 100) : ");
|
||||
essai = console.readLine();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Erreur de console.");
|
||||
}
|
||||
try {
|
||||
for (int i = 2; i != 6; i++) {
|
||||
if (Integer.parseInt(essai) > aDeviner) {
|
||||
System.out.println("-");
|
||||
}
|
||||
|
||||
else if (Integer.parseInt(essai) == aDeviner) {
|
||||
break;
|
||||
}
|
||||
|
||||
else {
|
||||
System.out.println("+");
|
||||
}
|
||||
System.out.println("Essai n°" + i + " : Veuillez entrer un nombre (1 à 100) : ");
|
||||
essai = console.readLine();
|
||||
}
|
||||
|
||||
if (Integer.parseInt(essai) == aDeviner) {
|
||||
System.out.println("Nombre trouvé.");
|
||||
}
|
||||
else {
|
||||
System.out.println("Nombre non trouvé après 5 essais.");
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("Erreur de console.");
|
||||
} catch (NumberFormatException e2) {
|
||||
System.err.println("Veuillez n'entrer que des nombres.");
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP13/02_Image/Fenetre.class
Normal file
BIN
DEV2.1/TP13/02_Image/Fenetre.class
Normal file
Binary file not shown.
12
DEV2.1/TP13/02_Image/Fenetre.java
Normal file
12
DEV2.1/TP13/02_Image/Fenetre.java
Normal file
@@ -0,0 +1,12 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setSize(32, 35);
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(1, 1));
|
||||
this.add(new Image());
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP13/02_Image/Image.class
Normal file
BIN
DEV2.1/TP13/02_Image/Image.class
Normal file
Binary file not shown.
13
DEV2.1/TP13/02_Image/Image.java
Normal file
13
DEV2.1/TP13/02_Image/Image.java
Normal file
@@ -0,0 +1,13 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Image extends JComponent {
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
|
||||
LectureFichier fichier = new LectureFichier();
|
||||
secondPinceau.drawImage(fichier.getImage(), 0, 0, this);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP13/02_Image/LectureFichier.class
Normal file
BIN
DEV2.1/TP13/02_Image/LectureFichier.class
Normal file
Binary file not shown.
74
DEV2.1/TP13/02_Image/LectureFichier.java
Normal file
74
DEV2.1/TP13/02_Image/LectureFichier.java
Normal file
@@ -0,0 +1,74 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class LectureFichier {
|
||||
|
||||
private BufferedImage image;
|
||||
|
||||
public LectureFichier() {
|
||||
try {
|
||||
BufferedReader lecture = new BufferedReader(new FileReader("image.xpm"));
|
||||
|
||||
try {
|
||||
for (int i = 0; i != 3; i++) {
|
||||
lecture.readLine();
|
||||
}
|
||||
|
||||
String infos = lecture.readLine();
|
||||
infos = infos.replaceAll("\"", "");
|
||||
String[] infosTab = infos.split(" ");
|
||||
for (String info : infosTab) {
|
||||
System.out.println(info);
|
||||
}
|
||||
this.image = new BufferedImage(Integer.parseInt(infosTab[0]), Integer.parseInt(infosTab[1]), BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
char[] caracteres = new char[15];
|
||||
Color[] couleurs = new Color[15];
|
||||
|
||||
for (int i = 0; i != Integer.parseInt(infosTab[2]); i++) {
|
||||
String ligne = lecture.readLine();
|
||||
caracteres[i] = ligne.charAt(1);
|
||||
|
||||
int[] rgb = {
|
||||
Integer.parseInt(ligne.substring(6,8), 16),
|
||||
Integer.parseInt(ligne.substring(8,10), 16),
|
||||
Integer.parseInt(ligne.substring(10,12), 16)
|
||||
};
|
||||
|
||||
couleurs[i] = new Color(rgb[0], rgb[1], rgb[2]);
|
||||
|
||||
}
|
||||
|
||||
lecture.readLine();
|
||||
|
||||
for (int i = 0; i != Integer.parseInt(infosTab[1]); i++) {
|
||||
String ligne = lecture.readLine().replaceAll("\"", "");
|
||||
ligne = ligne.substring(0, ligne.length()-1);
|
||||
|
||||
for (int j = 0; j != ligne.length(); j++) {
|
||||
for (int k = 0; k != caracteres.length; k++) {
|
||||
if (caracteres[k] == ligne.charAt(j)) {
|
||||
this.image.setRGB(i, j, couleurs[k].getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.err.println("Erreur d'écriture");
|
||||
}
|
||||
|
||||
try {
|
||||
lecture.close();
|
||||
} catch (IOException e3) {
|
||||
System.err.println("Erreur de fermeture");
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
System.err.println("Erreur d'ouverture");
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
return this.image;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP13/02_Image/Main.class
Normal file
BIN
DEV2.1/TP13/02_Image/Main.class
Normal file
Binary file not shown.
6
DEV2.1/TP13/02_Image/Main.java
Normal file
6
DEV2.1/TP13/02_Image/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
56
DEV2.1/TP13/02_Image/image.xpm
Normal file
56
DEV2.1/TP13/02_Image/image.xpm
Normal file
@@ -0,0 +1,56 @@
|
||||
/* XPM */
|
||||
static char *test[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"32 35 15 1",
|
||||
" c #000000",
|
||||
". c #731810",
|
||||
"X c #A52918",
|
||||
"o c #FF5210",
|
||||
"O c #D64221",
|
||||
"+ c #FF8C10",
|
||||
"@ c #FFBD29",
|
||||
"# c #FFE739",
|
||||
"$ c #FFBD4A",
|
||||
"% c #FFFF63",
|
||||
"& c #9C8C8C",
|
||||
"* c #C6B5B5",
|
||||
"= c #B0D8D0",
|
||||
"- c #EFDEDE",
|
||||
"; c #FFFFFF",
|
||||
/* pixels */
|
||||
"================================",
|
||||
"================================",
|
||||
"=============O====o=============",
|
||||
"==============O==o#o============",
|
||||
"==============oO=o@o============",
|
||||
"==============ooOo+o============",
|
||||
"==========o===o+o=o=============",
|
||||
"=========o@o=Oo++o==============",
|
||||
"=========ooo=o+@+o==============",
|
||||
"==========o=O++@+oO=============",
|
||||
"============o+@#@o+O============",
|
||||
"===========O+@#;#+@+o===========",
|
||||
"===========O+#;;;+#@o===========",
|
||||
"===========o@;;;;@#o============",
|
||||
"=== =======..........======= ===",
|
||||
"== = = ==..XXOOooOOXX..== = = ==",
|
||||
"= = =.XXoOO OOoXX.= = =",
|
||||
"== XXXX % % XXXX ==",
|
||||
"=== oX XXX XXX Xo ===",
|
||||
"=====X o$X -& &- X$o X=====",
|
||||
"=====X o$$o ;;;;;; o$$o X=====",
|
||||
"===== Xoo$$$ -;oo;- $$$ooX =====",
|
||||
"===== OoX$Xoo ;;;; ooX$XoO =====",
|
||||
"===== Xo o O -;;- O o oX =====",
|
||||
"====== O O = -- = O O ======",
|
||||
"======= = *= o o =* = =======",
|
||||
"=========== * oooo * ===========",
|
||||
"=========== oooooo ===========",
|
||||
"========== XooooooX ==========",
|
||||
"========= X XooooooX X =========",
|
||||
"========= OooOOOOOOooO =========",
|
||||
"========== oooooooo ==========",
|
||||
"============ ============",
|
||||
"================================",
|
||||
"================================"
|
||||
};
|
Reference in New Issue
Block a user