Bonjour,
Voila j'ai un probleme d'echelle pour l'affichage de mon graphe, je precise:
J'ai un fichier avec des coordonnees de points (des reels) j'ai lu quelque part que avec java on ne pouvais representer que des entiers, donc en recuperant tous mes points je les multiplie par 1000 ou 10000 pour avoir plus de precision. Mais quand je trace mes points ils ne sont pas tous representes car la plus part sont en dehors de la fenetre.
Merci Par avance.
Cordialement deccan
PS: Je vous joint mon code.
Classe main:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 package graphe2; import java.awt.Polygon; import java.io.*; public class CourbeMath { public Polygon MesPolygones[]; public CourbeMath() { CalculPoints(); } public int NbPoly(){ //retourne le nombre de triangles dans le fichier String chaine=""; String fich ="/home/makarov/four.msh"; File fichier = new File(fich); //lecture du fichier texte try{ InputStream ips=new FileInputStream(fichier); InputStreamReader ipsr=new InputStreamReader(ips); BufferedReader br=new BufferedReader(ipsr); String ligne; ligne=br.readLine(); chaine+=ligne; br.close(); } catch (Exception e){ System.out.println(e.toString()); } String delims = "[ ]+"; String[] tokens = chaine.split(delims); int aInt = Integer.parseInt(tokens[1]); return aInt; } private void CalculPoints() { MesPolygones = new Polygon[this.NbPoly()]; String fich ="/home/makarov/plot"; File fichier = new File(fich); int N=this.NbPoly(); try{ InputStream ips=new FileInputStream(fichier); InputStreamReader ipsr=new InputStreamReader(ips); BufferedReader br=new BufferedReader(ipsr); int k=0; for(int i = 0 ; i < 6*N ; i=i+6) { int x[] = new int[3]; int y[]= new int[3]; for(int j=0; j<3;j++){ String ligne; String chaine=""; ligne=br.readLine(); chaine+=ligne; String delims = "[ ]+"; String[] tokens = chaine.split(delims); double xInt = Double.parseDouble(tokens[0]); double yInt = Double.parseDouble(tokens[1]); xInt=xInt*1000; yInt=yInt*1000; x[j]=(int)xInt; y[j]=(int)yInt; System.out.println("coordonnees"+x[j]+","+y[j]); } br.readLine(); br.readLine(); br.readLine(); MesPolygones[i-k*5]=new Polygon(x,y,3); k++; } br.close(); } catch (Exception e){ System.out.println(e.toString()); } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 package graphe2; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class principal extends JPanel{ private CourbeMath C; public principal() {C= new CourbeMath();} public void paint(Graphics g){ for(int i=0;i<C.NbPoly();i++){ g.drawPolygon(C.MesPolygones[i]); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame frame = new JFrame(); frame.getContentPane().add(new principal()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(10000, 10000); frame.pack(); frame.setVisible(true); } }






Répondre avec citation




quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.
suivez 



Partager