Bonjour à tous,
Je travaille sous système Linux ubuntu Jaunty-9.04
Mon EDI est Netbeans 6.5.1
Je souhaite inclure des graphiques JFreeChart dans mes applets.
J'ai lu la doc, cela n'a pas l'air très compliqué, et j'ai fait un premier essai:
Voici le code:
Dans l'appletviewer de l'EDI cela marche parfaitement.
Code java : 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * fibonacci.java * * Created on 10 juil. 2009, 07:31:03 */ /** * * @author gilles */ import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartFactory; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import java.awt.Graphics; import java.awt.Graphics2D; import java.util.LinkedList; public class fibonacci extends java.applet.Applet { DefaultCategoryDataset dataset; JFreeChart chart; String serie1 = "u(n+1)=u(n)+u(n-1)"; LinkedList indicesi = new LinkedList(); LinkedList indicess = new LinkedList(); int curindex; private double fibonacci(int n) { if (n == 0) { return 1; } if (n == 1) { return 1; } return fibonacci(n - 1) + fibonacci(n - 2); } /** Initializes the applet defsuites1 */ public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } this.setSize(600, 400); dataset = new DefaultCategoryDataset(); curindex = 1; for (int i = 0; i < curindex; i++) { indicesi.add(i); indicess.add("" + i); dataset.addValue(fibonacci((Integer) indicesi.get(i)), serie1, (String) indicess.get(i)); } chart = ChartFactory.createBarChart("Visualisation suite de Fibonacci", "indice n", "u(n)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setAntiAlias(true); } @Override public void paint(Graphics g) { super.paint(g); if (chart != null) { chart.draw((Graphics2D) g, getBounds()); //repaints the whole chart } jToolBar1.repaint(); } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jToolBar1 = new javax.swing.JToolBar(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jToolBar1.setRollover(true); jButton1.setText("Rec."); jButton1.setFocusable(false); jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton1MouseClicked(evt); } }); jToolBar1.add(jButton1); jButton2.setText("Suiv."); jButton2.setFocusable(false); jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jButton2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton2MouseClicked(evt); } }); jToolBar1.add(jButton2); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(318, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(278, Short.MAX_VALUE) .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)) ); }// </editor-fold> private void jButton2MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: int i = curindex; indicesi.add(i); indicess.add("" + i); dataset.addValue(fibonacci((Integer) indicesi.get(i)), serie1, (String) indicess.get(i)); curindex++; repaint(); } private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: indicesi.clear(); indicess.clear(); dataset.clear(); curindex = 1; for (int i = 0; i < curindex; i++) { indicesi.add(i); indicess.add("" + i); dataset.addValue(fibonacci((Integer) indicesi.get(i)), serie1, (String) indicess.get(i)); } repaint(); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JToolBar jToolBar1; // End of variables declaration }
Maintenant quand je veux lancer l'applet depuis un fichier html, en reprenant directement le code généré.
Dans le répertoire 'classes' il y a les 4 fichiers générés suivants:
Code html : 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 <HTML> <HEAD> <TITLE>Applet HTML Page</TITLE> </HEAD> <BODY> <!-- *** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER *** If you need to modify this HTML launcher file (e.g., to add applet parameters), copy it to where your applet class is found in the SRC folder. If you do this, the IDE will use it when you run or debug the applet. Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in the Packaging page in the Project Properties dialog. For more information see the online help. --> <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3> <P> <APPLET codebase="classes" code="fibonacci.class" width=350 height=200></APPLET> </P> <HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT> </BODY> </HTML>
fibonacci.class
fibonacci$1.class
fibonacci$2.class
fibonacci$3.class
Tout cela a été généré automatiquement.
Cela ne fonctionne plus !
La console java me donne les erreurs suivantes:
J'en conclus qu'il manque des .class ou des .jar quelque part. Cela fonctionne en développement parce que j'ai ajouté à l'EDI les librairies, les sources, les javadoc, mais pas en production.Java Plug-in 1.6.0_13
Utilisation de la version JRE 1.6.0_13 Java HotSpot(TM) 64-Bit Server VM
Répertoire d'accueil de l'utilisateur = /home/gilles
----------------------------------------------------
c: effacer la fenêtre de la console
f: finaliser les objets de la file d'attente de finalisation
g: libérer la mémoire
h: afficher ce message d'aide
l: vider la liste des chargeurs de classes
m: imprimer le relevé d'utilisation de la mémoire
o: déclencher la consignation
q: masquer la console
r: recharger la configuration des politiques
s: vider les propriétés système et déploiement
t: vider la liste des threads
v: vider la pile des threads
x: effacer le cache de chargeurs de classes
0-5: fixer le niveau de traçage à <n>
----------------------------------------------------
java.lang.NoClassDefFoundError: org/jfree/data/category/CategoryDataset
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:2838)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1380)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: org.jfree.data.category.CategoryDataset
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 8 more
Caused by: java.io.FileNotFoundException: /home/gilles/NetBeansProjects/analyse_reelle/defsuites1/build/classes/org/jfree/data/category/CategoryDataset.class (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at sun.net.http://www.protocol.file.FileURLConn...ection.java:70)
at sun.net.http://www.protocol.file.FileURLConn...ction.java:161)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Applet2ClassLoader.java:468)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Applet2ClassLoader.java:46)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Applet2ClassLoader.java:126)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:123)
... 11 more
Exception : java.lang.NoClassDefFoundError: org/jfree/data/category/CategoryDataset
Quelqu'un peut-il me dire ce que je dois ajouter et où. S'il s'agit de fichiers à compiler, vous seriez aimable de me donner la manip à faire.
Merci d'avance.
Partager