Advertisement
Guest User

Untitled

a guest
Dec 21st, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.78 KB | None | 0 0
  1.  
  2.  
  3. package dataPoints;
  4. import geomD2.DroiteD2;
  5. import geomD2.PointsD2;
  6.  
  7. import java.io.FileReader;
  8. import java.io.LineNumberReader;
  9. import java.util.ArrayList;
  10. import java.util.StringTokenizer;
  11.  
  12. public class DataPoints {
  13. /**
  14. *
  15. */
  16. private static final long serialVersionUID = 1L;
  17. double min_x, min_y, max_x, max_y;
  18. ArrayList <PointsD2> vectPoint;
  19. public DataPoints(String fichier){
  20. LineNumberReader lecteurLignes = null;
  21. try{
  22.  
  23. lecteurLignes = new LineNumberReader (new FileReader(fichier));
  24. String ligneTexte = null;
  25. vectPoint = new ArrayList<PointsD2>();
  26. while ((ligneTexte = lecteurLignes.readLine()) != null) {
  27. StringTokenizer st = new StringTokenizer(ligneTexte);
  28.  
  29. if (st.countTokens() == 2) {
  30. //stoker les points dans le vecteur courant
  31. Double X = new Double(st.nextToken());
  32. Double Y = new Double(st.nextToken());
  33. PointsD2 Point = new PointsD2(X,Y);
  34. vectPoint.add(Point);
  35. }
  36. if (st.countTokens() == 4 ) {
  37. Double X = new Double(st.nextToken());
  38. Double Y = new Double(st.nextToken());
  39. PointsD2 Point = new PointsD2(X,Y);
  40. Double X1 = new Double(st.nextToken());
  41. Double Y1 = new Double(st.nextToken());
  42.  
  43. PointsD2 Point2 = new PointsD2(X1,Y1);
  44. new DroiteD2(Point,Point2);
  45.  
  46.  
  47. }
  48. }
  49.  
  50.  
  51. }
  52. catch(Exception e) { e.printStackTrace(); }
  53. min_max();
  54. }
  55.  
  56. private void min_max() {
  57. // trouver les coordonnÈes extrÍmes {min_x}, {max_x}, {min_y},
  58. // {max_y} des points stockÈs dans le vecteur courant: je n'arrive pas
  59.  
  60.  
  61. }
  62. }
  63. package dataPoints;
  64. import geomD2.DroiteD2;
  65. import geomD2.PointsD2;
  66.  
  67. import java.awt.*;
  68. import java.util.ArrayList;
  69. import java.util.Iterator;
  70.  
  71. import javax.swing.JComponent;
  72. import javax.swing.JPanel;
  73.  
  74.  
  75.  
  76. public class DessinPoints extends JPanel {
  77.  
  78.  
  79.     /**
  80.      *
  81.      */
  82.     private static final long serialVersionUID = 1L;
  83.     DataPoints listPts;
  84.     int bord; // taille des bords
  85.     int enveloppe; // dimension des rectangles
  86.    
  87.    
  88.     public DessinPoints (DataPoints pts, int largeur, int hauteur, int bord, int enveloppe) {
  89.         //this.listPts = pts;
  90.         this.bord = bord;
  91.         this.enveloppe = enveloppe;
  92.        
  93.  
  94.     }
  95.     @SuppressWarnings("null")
  96.     @Override
  97.     public void paintComponent (Graphics g) {
  98.    
  99.         super.paintComponent(g);
  100.         g.setXORMode(Color.RED);
  101.         JComponent tailleOriginal = null;
  102.         Dimension tailleSuivante = new Dimension (this.getSize()); //Affectation de la nouvelle taille de la fen√™tre
  103.        
  104.            
  105.        
  106.         double factEchX = tailleSuivante.getWidth()/tailleOriginal.getWidth(); //calcule du facteur de l'√©chelle sur l'axe X
  107.         double factEchY = tailleSuivante.getHeight()/tailleOriginal.getHeight(); //calcule de facteur de l'√©chelle sur l'axe Y
  108.        
  109.         for (int i=0;i<listPts.size();i++){
  110.             ArrayList<PointsD2> ptLu = (ArrayList<PointsD2>)listPts.get(i); //Liste des point courants
  111.             //Test si il y a 1 ou 2 point pour l'affichage de ses dernier avec ou sans la droite
  112.             if(ptLu.size()==1){
  113.                 //Affichage des points
  114.                 //System.out.println((int)(ptLu.get(0).getX().intValue()*factEchX),(int)(ptLu.get(0).getY().intValue()*factEchY),enveloppe,enveloppe);;
  115.                 g.drawRect((int)(ptLu.get(0).getX().intValue()*factEchX),(int)(ptLu.get(0).getY().intValue()*factEchY),enveloppe,enveloppe);
  116.             }
  117.             if(ptLu.size()==2){
  118.                 int milieuPointX1,milieuPointY1,milieuPointX2,milieuPointY2; //Coordin√©es central des points pour l'affichage central de la droite
  119.  
  120.                 //definition du milieu des points
  121.                 milieuPointX1 = ptLu.get(0).getX().intValue()-enveloppe/2;
  122.                 milieuPointY1 = ptLu.get(0).getY().intValue()-enveloppe/2;
  123.                 milieuPointX2 = ptLu.get(1).getX().intValue()-enveloppe/2;
  124.                 milieuPointY2 = ptLu.get(1).getY().intValue()-enveloppe/2;
  125.  
  126.                 //Affichage des points
  127.                 g.drawRect((int)(milieuPointX1*factEchX),(int)(milieuPointY1*factEchY),enveloppe,enveloppe);
  128.                 g.drawRect((int)(milieuPointX2*factEchX),(int)(milieuPointY2*factEchY),enveloppe,enveloppe);
  129.            
  130.                 //Cr√©ation de la droite
  131.                 DroiteD2 droite = new DroiteD2 (ptLu.get(0),ptLu.get(1));
  132.                 //Affichage de la droite
  133.                 g.drawLine((int)(droite.getIntersectionX().intValue()*factEchX),0,0,(int)(droite.getIntersectionY().intValue()*factEchY));
  134.             }
  135.         }              
  136.    
  137.  
  138.  
  139.  
  140.    
  141.        
  142.     }
  143.    
  144.  
  145.                 }
  146.  
  147.  
  148.  
  149.  
  150.  
  151. import java.awt.BorderLayout;
  152.  
  153. import javax.swing.JFrame;
  154.  
  155. import dataPoints.DataPoints;
  156. import dataPoints.DessinPoints;
  157.  
  158. public class Grapheur {
  159. public static void main(String[] args) {
  160. DataPoints listePts = new DataPoints ("fichier.txt");
  161. //System.out.println(listePts);
  162. DessinPoints monGraphe = new DessinPoints(listePts,600,400,10,10);
  163. JFrame f = new JFrame();
  164. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  165. f.setLayout(new BorderLayout());
  166. f.add(monGraphe, BorderLayout.CENTER);
  167. f.setTitle("Grapheur");
  168.  
  169. int bordure = 0;
  170. f.setSize(400, 400);
  171. f.setVisible(true);
  172.  
  173.  
  174. }
  175.  
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement