TP
This commit is contained in:
16
DEV2.1/TP12/02_Polygone/Fenetre.java
Normal file
16
DEV2.1/TP12/02_Polygone/Fenetre.java
Normal file
@@ -0,0 +1,16 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
|
||||
public Fenetre() {
|
||||
this.setSize(500, 600);
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(1, 1));
|
||||
LectureFichier lecture = new LectureFichier();
|
||||
EcritureFichier ecriture = new EcritureFichier("test", lecture.getCoordY(), lecture.getNbPoints());
|
||||
this.add(new Polygone(lecture.getCoordX(), lecture.getCoordY(), lecture.getNbPoints()));
|
||||
EcritureFichier ecriture = new EcritureFichier(lecture.getCoordX(), lecture.getCoordY(), lecture.getNbPoints());
|
||||
}
|
||||
}
|
54
DEV2.1/TP12/02_Polygone/LectureFichier.java
Normal file
54
DEV2.1/TP12/02_Polygone/LectureFichier.java
Normal file
@@ -0,0 +1,54 @@
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
public class LectureFichier {
|
||||
|
||||
private int[] coordX;
|
||||
private int[] coordY;
|
||||
private int nbPoints;
|
||||
|
||||
public LectureFichier() {
|
||||
|
||||
try {
|
||||
FileInputStream fichier = new FileInputStream("polygone.bin");
|
||||
DataInputStream flux = new DataInputStream(fichier);
|
||||
|
||||
this.coordX = new int[flux.available()/8];
|
||||
this.coordY = new int[flux.available()/8];
|
||||
this.nbPoints = flux.available()/8;
|
||||
|
||||
int compteur = 0;
|
||||
|
||||
try {
|
||||
while (flux.available() > 0) {
|
||||
this.coordX[compteur] = flux.readInt();
|
||||
this.coordY[compteur] = flux.readInt();
|
||||
compteur++;
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
System.out.println("Erreur de lecture");
|
||||
}
|
||||
|
||||
try {
|
||||
flux.close();
|
||||
} catch (IOException e3) {
|
||||
System.out.println("Erreur de fermeture");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Erreur d'ouverture");
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getCoordX() {
|
||||
return this.coordX;
|
||||
}
|
||||
|
||||
public int[] getCoordY() {
|
||||
return this.coordY;
|
||||
}
|
||||
|
||||
public int getNbPoints() {
|
||||
return this.nbPoints;
|
||||
}
|
||||
}
|
6
DEV2.1/TP12/02_Polygone/Main.java
Normal file
6
DEV2.1/TP12/02_Polygone/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
28
DEV2.1/TP12/02_Polygone/Polygone.java
Normal file
28
DEV2.1/TP12/02_Polygone/Polygone.java
Normal file
@@ -0,0 +1,28 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Polygone extends JComponent {
|
||||
|
||||
private int[] coordX;
|
||||
private int[] coordY;
|
||||
private int nbPoints;
|
||||
|
||||
public Polygone(int[] coordX, int[] coordY, int nbPoints) {
|
||||
this.coordX = coordX;
|
||||
this.coordY = coordY;
|
||||
this.nbPoints = nbPoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
|
||||
if (this.isOpaque()) {
|
||||
secondPinceau.setColor(this.getBackground());
|
||||
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
secondPinceau.setColor(Color.BLUE);
|
||||
secondPinceau.fillPolygon(this.coordX, this.coordY, this.nbPoints);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP12/02_Polygone/polygone.bin
Normal file
BIN
DEV2.1/TP12/02_Polygone/polygone.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user