TP 15/16
This commit is contained in:
parent
c0b06ea837
commit
79791b395c
BIN
APL2.1/TP15/Devinette/Devinette.class
Normal file
BIN
APL2.1/TP15/Devinette/Devinette.class
Normal file
Binary file not shown.
55
APL2.1/TP15/Devinette/Devinette.java
Normal file
55
APL2.1/TP15/Devinette/Devinette.java
Normal file
@ -0,0 +1,55 @@
|
||||
package Devinette;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class Devinette {
|
||||
public static void main(String[] args) {
|
||||
int rand = 0;
|
||||
try (DataInputStream ois = new DataInputStream(new FileInputStream("/dev/random"))){
|
||||
try {
|
||||
rand = ois.readInt() % 100 + 1;
|
||||
System.out.println(rand);
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
ois.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);
|
||||
System.exit(1);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
try (BufferedReader ois = new BufferedReader(new InputStreamReader(System.in))) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int guess = Integer.parseInt(ois.readLine());
|
||||
System.out.println(guess + " " + rand);
|
||||
|
||||
if (guess == rand) {
|
||||
System.out.println("Gagné !");
|
||||
return;
|
||||
} else if (guess > rand) {
|
||||
System.out.println("-");
|
||||
} else if (guess < rand) {
|
||||
System.out.println("+");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Perdu !");
|
||||
} catch (IOException e) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
BIN
APL2.1/TP15/Image/AwesomeImage.class
Normal file
BIN
APL2.1/TP15/Image/AwesomeImage.class
Normal file
Binary file not shown.
22
APL2.1/TP15/Image/AwesomeImage.java
Normal file
22
APL2.1/TP15/Image/AwesomeImage.java
Normal file
@ -0,0 +1,22 @@
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.*;
|
||||
import java.awt.Image;
|
||||
|
||||
public class AwesomeImage extends JPanel {
|
||||
private Image img;
|
||||
public AwesomeImage(Image a) {
|
||||
super();
|
||||
this.img = a;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics newG = g.create();
|
||||
if (this.isOpaque()) {
|
||||
newG.setColor(this.getBackground());
|
||||
newG.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
newG.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
|
||||
}
|
||||
}
|
BIN
APL2.1/TP15/Image/Image.class
Normal file
BIN
APL2.1/TP15/Image/Image.class
Normal file
Binary file not shown.
61
APL2.1/TP15/Image/Image.java
Normal file
61
APL2.1/TP15/Image/Image.java
Normal file
@ -0,0 +1,61 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
|
||||
public class Image {
|
||||
public static void main(String[] args) {
|
||||
try (BufferedReader r = new BufferedReader(new FileReader("image.xpm"))) {
|
||||
r.readLine(); r.readLine(); r.readLine(); //On skip les 3 première lignes.
|
||||
String[] infos = r.readLine().replaceAll("[\" ]", " ").trim().split(" ");
|
||||
System.out.println(Arrays.toString(infos));
|
||||
int columns = Integer.parseInt(infos[0]);
|
||||
int rows = Integer.parseInt(infos[1]);
|
||||
int colorCount = Integer.parseInt(infos[2]);
|
||||
int charPerPixel = Integer.parseInt(infos[3]);
|
||||
|
||||
char[] paletteId = new char[colorCount];
|
||||
Color[] palette = new Color[colorCount];
|
||||
|
||||
for (int i = 0; i < colorCount; i++) {
|
||||
String colorInfos = r.readLine().replaceAll("[\"]", "");
|
||||
paletteId[i] = colorInfos.charAt(0);
|
||||
System.out.println(colorInfos.substring(4, 11));
|
||||
|
||||
palette[i] = Color.decode(colorInfos.substring(4, 11));
|
||||
}
|
||||
|
||||
r.readLine(); //On skip la ligne pixels.
|
||||
BufferedImage bi = new BufferedImage(columns, rows, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
for (int i = 0; i < rows; i++) {
|
||||
String row = r.readLine().replaceAll("\"", "");
|
||||
for (int y = 0; y < columns; y++) {
|
||||
char a = row.charAt(y);
|
||||
for (int j = 0; j < paletteId.length; j++) {
|
||||
if (paletteId[j] == a) {
|
||||
bi.setRGB(y, i, palette[j].getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JFrame j = new JFrame();
|
||||
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
j.setSize(500 + 50, 500 + 50);
|
||||
j.setLayout(null);
|
||||
|
||||
AwesomeImage a = new AwesomeImage(bi);
|
||||
a.setLocation(10, 10);
|
||||
a.setSize(500, 500);
|
||||
j.add(a);
|
||||
|
||||
j.setVisible(true);
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
56
APL2.1/TP15/Image/image.xpm
Normal file
56
APL2.1/TP15/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 ==========",
|
||||
"============ ============",
|
||||
"================================",
|
||||
"================================"
|
||||
};
|
BIN
APL2.1/TP16/Conversion/Conversion.class
Normal file
BIN
APL2.1/TP16/Conversion/Conversion.class
Normal file
Binary file not shown.
53
APL2.1/TP16/Conversion/Conversion.java
Normal file
53
APL2.1/TP16/Conversion/Conversion.java
Normal file
@ -0,0 +1,53 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Conversion {
|
||||
public static void main(String[] args) {
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(args[0]))) {
|
||||
String fullContent = "";
|
||||
String htmlContent = "";
|
||||
|
||||
{
|
||||
int i = 0;
|
||||
boolean canRead = true;
|
||||
while (canRead) {
|
||||
String content = br.readLine();
|
||||
if (content != null) {
|
||||
if (i == 0) {
|
||||
fullContent += content;
|
||||
} else {
|
||||
fullContent += "<br>" + content;
|
||||
}
|
||||
i++;
|
||||
} else canRead = false;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(fullContent);
|
||||
|
||||
br.close();
|
||||
|
||||
try (BufferedReader br2 = new BufferedReader(new FileReader("base.html"))) {
|
||||
htmlContent = br2.readLine();
|
||||
br2.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
htmlContent = htmlContent.replaceAll("TOREPLACE", fullContent);
|
||||
System.out.println(htmlContent);
|
||||
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(args[0] + ".html"))) {
|
||||
bw.write(htmlContent);
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
1
APL2.1/TP16/Conversion/base.html
Normal file
1
APL2.1/TP16/Conversion/base.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"><title>OwO</title></head><body><p>TOREPLACE</p></body></html>
|
9
APL2.1/TP16/Conversion/funny.txt
Normal file
9
APL2.1/TP16/Conversion/funny.txt
Normal file
@ -0,0 +1,9 @@
|
||||
jiGJIOPAEJIOGOJIEAGJIOAEIO
|
||||
ZFIAJPIFPJIAZJPF
|
||||
|
||||
AQG
|
||||
AQGAZ
|
||||
GAZ
|
||||
GAZAZ
|
||||
GAZAZ
|
||||
GAZ
|
1
APL2.1/TP16/Conversion/funny.txt.html
Normal file
1
APL2.1/TP16/Conversion/funny.txt.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"><title>OwO</title></head><body><p>jiGJIOPAEJIOGOJIEAGJIOAEIO<br>ZFIAJPIFPJIAZJPF<br><br>AQG<br>AQGAZ<br>GAZ<br>GAZAZ<br>GAZAZ<br>GAZ</p></body></html>
|
BIN
APL2.1/TP16/Couleurs/Couleurs.class
Normal file
BIN
APL2.1/TP16/Couleurs/Couleurs.class
Normal file
Binary file not shown.
70
APL2.1/TP16/Couleurs/Couleurs.java
Normal file
70
APL2.1/TP16/Couleurs/Couleurs.java
Normal file
@ -0,0 +1,70 @@
|
||||
import java.awt.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Couleurs extends JPanel {
|
||||
int max;
|
||||
int index1 = -1;
|
||||
int index2 = -1;
|
||||
String[] nameList;
|
||||
Color[] colorList;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame f = new JFrame("OwO");
|
||||
f.setSize(300, 300);
|
||||
f.setLocation(100, 100);
|
||||
f.setResizable(false);
|
||||
f.add(new Couleurs());
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setVisible(true);
|
||||
}
|
||||
|
||||
public Couleurs() {
|
||||
super();
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader("rgb.txt"))) {
|
||||
br.mark(2000000000);
|
||||
this.max = (int)br.lines().count();
|
||||
br.reset();
|
||||
this.nameList = new String[max];
|
||||
this.colorList = new Color[max];
|
||||
System.out.println(br.readLine());
|
||||
|
||||
for (int i = 0; i < max-1; i++) {
|
||||
String[] infos = br.readLine().trim().split("[ \t]+");
|
||||
nameList[i] = infos[3];
|
||||
colorList[i] = new Color(Integer.parseInt(infos[0]), Integer.parseInt(infos[1]), Integer.parseInt(infos[2]));
|
||||
}
|
||||
|
||||
Random r = new Random();
|
||||
this.index1 = r.nextInt(max);
|
||||
this.index2 = r.nextInt(max);
|
||||
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics newG = g.create();
|
||||
|
||||
if (this.isOpaque()) {
|
||||
newG.setColor(this.getBackground());
|
||||
newG.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
if (index1 != -1 && index2 != -1) {
|
||||
newG.setColor(colorList[index1]);
|
||||
newG.fillPolygon(new int[] {0, 0, this.getWidth()}, new int[] {0, this.getHeight(), this.getHeight()}, 3);
|
||||
|
||||
newG.setColor(colorList[index2]);
|
||||
newG.fillPolygon(new int[] {0, this.getWidth(), this.getWidth()}, new int[] {0, 0, this.getHeight()}, 3);
|
||||
}
|
||||
}
|
||||
}
|
3
APL2.1/TP16/Couleurs/Listener.java
Normal file
3
APL2.1/TP16/Couleurs/Listener.java
Normal file
@ -0,0 +1,3 @@
|
||||
public class Listener extends MouseListener {
|
||||
|
||||
}
|
753
APL2.1/TP16/Couleurs/rgb.txt
Normal file
753
APL2.1/TP16/Couleurs/rgb.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user