Bonjour à tous,
Je suis en train de produire un programme pour valider mon master qui ressemble à une simulation aérienne, et je dois afficher des graphiques en temps réel sur l'état du joystick et des surfaces de contrôle de l'avion. J'ai cru comprendre que jFreeChart était la meilleur solution pour cela avec la fonction XYSplineRender (si je me trompe, dites-le moi).
Seulement voila, j'ai commencé à faire mon IHM avec l'interface de NetBeans (version 7.2), qui pour le moment se compose d'une JFrame avec 3 JPanel et 1 JTabbedPane, qui lui même est composé de 3 JPanel. Dans une des JPanel qui est dans le JTabbedPane, j'ai 3 JPanels qui sont les trois emplacements où j'aimerais afficher un graphique.
J'ai crée un objet Chart pour les graphiques (générés aléatoirement pour le moment):
Qui est appelé dans l'objet Window (qui est en fait l'IHM) à ce moment la:
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 package comet; import java.awt.BorderLayout; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; public class Chart{ private XYSeriesCollection dataset; private JFreeChart chart; private JPanel content; private ChartPanel chartPanel; public Chart (final String title) { dataset = createRandomDataset("Serie"); chart = ChartFactory.createXYLineChart("title", "Axis 1", "Axis 2", (XYDataset) dataset, PlotOrientation.VERTICAL, true, true, false); content = new JPanel(new BorderLayout()); chartPanel = new ChartPanel(chart); content.add(chartPanel); } private XYSeriesCollection createRandomDataset(String name) { XYSeries series = new XYSeries(name); double value = 25.0; for (int i = 0; i < 50; i++) { series.add(i, value); value = value * (1.0 + Math.random() / 100); } return new XYSeriesCollection(series); } public JPanel getContent() { return content; } }
Seulement voila, les graphiques ne sont pas affichés:
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 public class Window extends javax.swing.JFrame { /** * Creates new form Window */ public Window(String name, boolean buttons, int buttonNumber, boolean thumb) { initComponents(); this.setLocationRelativeTo(null); this.name.setText(name); this.buttons.setText(String.valueOf(buttons)); this.buttonsNumber.setText(String.valueOf(buttonNumber)); this.thumb.setText(String.valueOf(thumb)); initCharts(); this.setVisible(true); } private void initCharts() { Chart test1 = new Chart("Coucou 01"); JPanel graphic1 = test1.getContent(); joystickChartPanel.add(graphic1); Chart test2 = new Chart("Coucou 02"); JPanel graphic2 = test2.getContent(); fcsChartPanel.add(graphic2); Chart test3 = new Chart("Coucou 03"); JPanel graphic3 = test3.getContent(); fmChartPanel.add(graphic3); } // [...] Le code continue...
Par contre, si j'essaye avec un main simple, sa fonctionne...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 public static void main(String[] args) { JFrame frame = new JFrame("Demo ChartPanel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Graphics test = new Graphics("coucou"); JPanel graphic1 = test.getContent(); JPanel joystickChartPanel = new JPanel(); joystickChartPanel.add(graphic1); frame.getContentPane().add(joystickChartPanel); frame.pack(); frame.setVisible(true); }
Quelqu'un peut m'aider?
Merci d'avance!!
Partager