Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dataPoints;
- import geomD2.DroiteD2;
- import geomD2.PointsD2;
- import java.io.FileReader;
- import java.io.LineNumberReader;
- import java.util.ArrayList;
- import java.util.StringTokenizer;
- public class DataPoints {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- double min_x, min_y, max_x, max_y;
- ArrayList <PointsD2> vectPoint;
- public DataPoints(String fichier){
- LineNumberReader lecteurLignes = null;
- try{
- lecteurLignes = new LineNumberReader (new FileReader(fichier));
- String ligneTexte = null;
- vectPoint = new ArrayList<PointsD2>();
- while ((ligneTexte = lecteurLignes.readLine()) != null) {
- StringTokenizer st = new StringTokenizer(ligneTexte);
- if (st.countTokens() == 2) {
- //stoker les points dans le vecteur courant
- Double X = new Double(st.nextToken());
- Double Y = new Double(st.nextToken());
- PointsD2 Point = new PointsD2(X,Y);
- vectPoint.add(Point);
- }
- if (st.countTokens() == 4 ) {
- Double X = new Double(st.nextToken());
- Double Y = new Double(st.nextToken());
- PointsD2 Point = new PointsD2(X,Y);
- Double X1 = new Double(st.nextToken());
- Double Y1 = new Double(st.nextToken());
- PointsD2 Point2 = new PointsD2(X1,Y1);
- new DroiteD2(Point,Point2);
- }
- }
- }
- catch(Exception e) { e.printStackTrace(); }
- min_max();
- }
- private void min_max() {
- // trouver les coordonnÈes extrÍmes {min_x}, {max_x}, {min_y},
- // {max_y} des points stockÈs dans le vecteur courant: je n'arrive pas
- }
- }
- package dataPoints;
- import geomD2.DroiteD2;
- import geomD2.PointsD2;
- import java.awt.*;
- import java.util.ArrayList;
- import java.util.Iterator;
- import javax.swing.JComponent;
- import javax.swing.JPanel;
- public class DessinPoints extends JPanel {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- DataPoints listPts;
- int bord; // taille des bords
- int enveloppe; // dimension des rectangles
- public DessinPoints (DataPoints pts, int largeur, int hauteur, int bord, int enveloppe) {
- //this.listPts = pts;
- this.bord = bord;
- this.enveloppe = enveloppe;
- }
- @SuppressWarnings("null")
- @Override
- public void paintComponent (Graphics g) {
- super.paintComponent(g);
- g.setXORMode(Color.RED);
- JComponent tailleOriginal = null;
- Dimension tailleSuivante = new Dimension (this.getSize()); //Affectation de la nouvelle taille de la fenêtre
- double factEchX = tailleSuivante.getWidth()/tailleOriginal.getWidth(); //calcule du facteur de l'échelle sur l'axe X
- double factEchY = tailleSuivante.getHeight()/tailleOriginal.getHeight(); //calcule de facteur de l'échelle sur l'axe Y
- for (int i=0;i<listPts.size();i++){
- ArrayList<PointsD2> ptLu = (ArrayList<PointsD2>)listPts.get(i); //Liste des point courants
- //Test si il y a 1 ou 2 point pour l'affichage de ses dernier avec ou sans la droite
- if(ptLu.size()==1){
- //Affichage des points
- //System.out.println((int)(ptLu.get(0).getX().intValue()*factEchX),(int)(ptLu.get(0).getY().intValue()*factEchY),enveloppe,enveloppe);;
- g.drawRect((int)(ptLu.get(0).getX().intValue()*factEchX),(int)(ptLu.get(0).getY().intValue()*factEchY),enveloppe,enveloppe);
- }
- if(ptLu.size()==2){
- int milieuPointX1,milieuPointY1,milieuPointX2,milieuPointY2; //Coordinées central des points pour l'affichage central de la droite
- //definition du milieu des points
- milieuPointX1 = ptLu.get(0).getX().intValue()-enveloppe/2;
- milieuPointY1 = ptLu.get(0).getY().intValue()-enveloppe/2;
- milieuPointX2 = ptLu.get(1).getX().intValue()-enveloppe/2;
- milieuPointY2 = ptLu.get(1).getY().intValue()-enveloppe/2;
- //Affichage des points
- g.drawRect((int)(milieuPointX1*factEchX),(int)(milieuPointY1*factEchY),enveloppe,enveloppe);
- g.drawRect((int)(milieuPointX2*factEchX),(int)(milieuPointY2*factEchY),enveloppe,enveloppe);
- //Création de la droite
- DroiteD2 droite = new DroiteD2 (ptLu.get(0),ptLu.get(1));
- //Affichage de la droite
- g.drawLine((int)(droite.getIntersectionX().intValue()*factEchX),0,0,(int)(droite.getIntersectionY().intValue()*factEchY));
- }
- }
- }
- }
- import java.awt.BorderLayout;
- import javax.swing.JFrame;
- import dataPoints.DataPoints;
- import dataPoints.DessinPoints;
- public class Grapheur {
- public static void main(String[] args) {
- DataPoints listePts = new DataPoints ("fichier.txt");
- //System.out.println(listePts);
- DessinPoints monGraphe = new DessinPoints(listePts,600,400,10,10);
- JFrame f = new JFrame();
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.setLayout(new BorderLayout());
- f.add(monGraphe, BorderLayout.CENTER);
- f.setTitle("Grapheur");
- int bordure = 0;
- f.setSize(400, 400);
- f.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement