DEV 2.2 & TP14
This commit is contained in:
BIN
APL2.1/TP14/Polygone/Polygone.class
Normal file
BIN
APL2.1/TP14/Polygone/Polygone.class
Normal file
Binary file not shown.
56
APL2.1/TP14/Polygone/Polygone.java
Normal file
56
APL2.1/TP14/Polygone/Polygone.java
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
||||
public class Polygone extends JPanel {
|
||||
private int[] x;
|
||||
private int[] y;
|
||||
|
||||
public Polygone() {
|
||||
super();
|
||||
|
||||
try {
|
||||
|
||||
FileInputStream fis = new FileInputStream("./polygone.bin");
|
||||
DataInputStream b = new DataInputStream(fis);
|
||||
|
||||
x = new int[b.available() / 8];
|
||||
y = new int[b.available() / 8];
|
||||
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] = b.readInt() * 2;
|
||||
y[i] = b.readInt() * 2;
|
||||
System.out.println(x[i] + ", " + y[i]);
|
||||
}
|
||||
|
||||
b.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
|
||||
Graphics secondPinceau = g.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(Color.BLACK);
|
||||
if (x != null) {
|
||||
secondPinceau.fillPolygon(x, y, x.length);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP14/Polygone/Test.class
Normal file
BIN
APL2.1/TP14/Polygone/Test.class
Normal file
Binary file not shown.
17
APL2.1/TP14/Polygone/Test.java
Normal file
17
APL2.1/TP14/Polygone/Test.java
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
JFrame j = new JFrame();
|
||||
j.setLocation(100, 100);
|
||||
j.setSize(500, 500);
|
||||
j.setLayout(null);
|
||||
Polygone p = new Polygone();
|
||||
p.setLocation(0, 0);
|
||||
p.setSize(400, 400);
|
||||
j.add(p);
|
||||
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
j.setVisible(true);
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP14/Polygone/polygone.bin
Normal file
BIN
APL2.1/TP14/Polygone/polygone.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user