Bonjour,
tout d'abord, dsl de venir poser cette question ici, mais même si le sujet semble avoir été bien étudié, je n'arrive toujours pas à bien comprendre.
Voilà mon problème :
Je dispose d'un int[] mes valeurs et je veux dessiner le graph f(n)=int[n]
dans une fenêtre.
Cette fenêtre ne constitue pas la fenêtre principal de mon programme, et elle doit pouvoir se réduire et se rouvrir, comme un onglet.
Il me semble que le plus naturel pour cela c'est d'utiliser graphics.drawLine(x1,y1,x2,y2)
le pb c'est que ma fenêtre est vide...
voici mon code, un très grand merci à ceux qui m'aideront
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 import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; /**@author <a href="mailto:tanguy.lapegue@emn.fr"> tanguy </a>*/ public class GraphiqueBourse extends JDialog{ public static final int DIM_H = 640; // Largeur en pixels de la fenetre public static final int DIM_V = 480; // Hauteur en pixels de la fenetre private static final long serialVersionUID = 1L; private int indice; private int[] mesValeurs=new int[GraphiqueBourse.NB_DONNEES]; private String[] mesDates=new String[GraphiqueBourse.NB_DONNEES]; public final static int NB_DONNEES=82; public GraphiqueBourse(){ super(); this.build(); Image img = new BufferedImage(150,52,BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D)img.getGraphics(); for(int i=0;i<GraphiqueBourse.NB_DONNEES-1;i++){ this.indice=i; this.paintComponent(g2d); } } public void build(){ File input =new File("donneeBourse.txt"); try { FileInputStream fis =new FileInputStream(input); InputStreamReader isr = new InputStreamReader(fis); BufferedReader br= new BufferedReader(isr); int i=0; while(br.ready()){ String ligne=br.readLine(); StringTokenizer st= new StringTokenizer(ligne); while(st.hasMoreTokens()){ String date; date=st.nextToken(); Integer valeur = new Integer(st.nextToken()); this.mesValeurs[i]=valeur; this.mesDates[i]=date; i++; } } } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private void paintComponent(Graphics g){ g.drawLine(this.indice,this.mesValeurs[this.indice],this.indice+1,this.mesValeurs[this.indice+1]); g.setColor(Color.red); this.setVisible(true); } }
Partager