Bonjour, je souhaite passer d'une applet à une application, j'ai donc rajouter un main du type:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
public static void main(java.lang.String[] args) {
	 Frame frMain = new Frame("Display");
     DisplayT mainApp =  new DisplayT();
     frMain.resize(100,100);
     frMain.show();
     mainApp.init();
     frMain.add("Center",mainApp);
l'erreur est la suivante:

Exception in thread "main" java.lang.NullPointerException
at java.applet.Applet.getParameter(Applet.java:168)
at hull.Applet3d.init(Applet3d.java:31)
at hull.DisplayT.init(DisplayT.java:80)
at hull.DisplayT.main(DisplayT.java:290)


et vient de mon init()...

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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
 
public void init() {
    mainPanel = new Panel();
    super.init();
    viewer.setViewLock(false);
    viewer.setView("Home");
    viewer.setColorVisibility(Points3d.color,false);
 
    validate();
 
    loadButton = new Button(loadMessage="Load data");
    if (!getBoolParameter("vrml")){
      mainPanel.add(loadButton);
    }
 
    if (getBoolParameter("controls")){
        add("South",mainPanel);
      }
}
 
Mon code entier est le suivant:
 
package hull;
 
/**
 * Applet allowing interactive investigation of hull algorithms
 */
 
 
import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
 
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.filechooser.FileSystemView;
 
import org.apache.commons.math.stat.descriptive.moment.Mean;
 
public class DisplayT extends Applet3d {
 
  Panel mainPanel;
  Choice modelChoice=null;
  Button moreButton;
  String moreMessage;
  Button loadButton;
  String loadMessage;
  Points3d points3d = new Points3d();
  private Point3dObject3d[] points = new Point3dObject3d[32];
  Object3dList model = new Object3dList(20);
  Axes axes = new Axes();
 
 
 
 
 Viewer makeViewer(){
	    Viewer v = new Viewer(this);
	    try {
	      String view = getParameter("view");
	      if (view != null){
		View3dInfo home = View3dInfo.fromString(view);
		v.setHome(home);
	      }
	    } catch (NumberFormatException e) {
	    }
	    Object3dAdaptor.normalColor=v.addColor("Normal","normal objects",getBoolParameter("Normal"),Color.green,true);
	    Triangle3d.backFaceColor=v.addColor(Color.blue);
	    Object3dAdaptor.addColor=v.addColor("Added","added objects",getBoolParameter("Added"),Color.red,true);
	    Object3dAdaptor.deleteColor=v.addColor("Deleted","deleted objects",getBoolParameter("Deleted"),Color.yellow,true);
	    Axes.color=v.addColor("Axes","coordinate axes",getBoolParameter("Axes"),Color.black,true);
	    Points3d.color=v.addColor("Points","input points",getBoolParameter("Points"),Color.black,true);
	    DivideAndConquer.leftColor=v.addColor("Left Hull","left convex hull",getBoolParameter("Left Hull"),Color.cyan,false);
	    DivideAndConquer.rightColor=v.addColor("Right Hull","right convex hull",getBoolParameter("Right Hull"),Color.magenta,false);
	    Object3dAdaptor.selectColor=v.addColor("Selected","selected object",getBoolParameter("Selected"),Color.cyan,false);
 
	    return v;
	  }
 
 
 
public void init() {
    mainPanel = new Panel();
    super.init();
    viewer.setViewLock(false);
    viewer.setView("Home");
    viewer.setColorVisibility(Points3d.color,false);
 
    validate();
 
    loadButton = new Button(loadMessage="Load data");
    if (!getBoolParameter("vrml")){
      mainPanel.add(loadButton);
    }
 
    if (getBoolParameter("controls")){
        add("South",mainPanel);
      }
}
 
 
 
  public boolean action(Event evt, Object arg) {
 
   if (evt.target == loadButton){
    	loadFile();
      return true;
    }
	   else {
      return super.action(evt,arg);
    }
  }
 
 
 
 
 
private void loadFile() {
	FileSystemView vueSysteme = FileSystemView.getFileSystemView(); 
	File home = vueSysteme.getHomeDirectory();
	//System.out.println(home);
 
	JFileChooser fc = new JFileChooser(home);
	String chaine=" ";
 
 
    int returnVal = fc.showOpenDialog(null);
 
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        System.out.println(file);
        loadData(file);
      }
}
 
 
 
private void loadData(File file) {
 
	try {
		InputStream ips=new FileInputStream(file); 
		InputStreamReader ipsr=new InputStreamReader(ips);
		BufferedReader br=new BufferedReader(ipsr);
 
		int i = 0;
		double x = 0;
		double y = 0;
		String ligne;
//on compte le nombre de lignes du fichier pour initiliser modimes1
 
		ligne = br.readLine();
 
		if (ligne != null){
			if(ligne.split(" ").length==9){
				Point3d pt1,pt2,pt3;
				int c=0;
				while (ligne !=null){
					System.out.println(c);
					pt1 = new Point3d (Double.parseDouble(ligne.split(" ")[0]),Double.parseDouble(ligne.split(" ")[1]),Double.parseDouble(ligne.split(" ")[2]));
					pt2 = new Point3d (Double.parseDouble(ligne.split(" ")[3]),Double.parseDouble(ligne.split(" ")[4]),Double.parseDouble(ligne.split(" ")[5]));
					pt3 = new Point3d (Double.parseDouble(ligne.split(" ")[6]),Double.parseDouble(ligne.split(" ")[7]),Double.parseDouble(ligne.split(" ")[8]));
					model.addElement(new Triangle3dPlus(pt1,pt2,pt3,c));
					c++;
					ligne = br.readLine();
				}
			}
			else if (ligne.split(" ").length==3){ 
				ArrayList<Point3d> serieRetenue = new ArrayList<Point3d>();
				while (ligne!=null){
					Point3d pt = new Point3d(Double.parseDouble(ligne.split(" ")[0]),Double.parseDouble(ligne.split(" ")[1]),Double.parseDouble(ligne.split(" ")[2]));
					serieRetenue.add(pt);
					ligne = br.readLine();
				    }
					Point3d[] pts=new Point3d[serieRetenue.size()];
					System.out.println(serieRetenue.size());
					for(int j=0;j<serieRetenue.size();j++)
						pts[j]=serieRetenue.get(j);
					for (int c=0; c <pts.length; c++) {
						model.addElement(new Point3dObject3d(pts[c]));
					}
 
				}
			else 
				System.out.println("Erreur dans le formatage des données.");
			}
		else 
			System.out.println("Empty file");
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
 
 
}
 
 
 
 
 
public boolean mouseEnter(Event e, int x, int y){
      showStatus("Hold the mouse button down and move the mouse to rotate the hull");
    return true;
  }
 
 
 
  /** override this method if we want a choice of models */
 
  public Object3dList selectModel() {
 
   model.addElement(axes);   
 System.out.println("Check       baba");
    return model;
  }
 
  /** defaultModel to display */
 
  public Object3dList defaultModel() {
    return selectModel();
  }
 
  public String[][] getDefaultParameters() {
    String[][] defaults = {
      // Array of arrays of strings describing each parameter.
      // Format: parameter name, value
 
      {"bgcolor", "ffffff"},
      {"controls", "on"},
      {"dimension", "3D"},
      {"model","quickHull"},
      {"distribution","In Sphere"},
      {"npoints","32"},
      {"Normal","on"},
      {"Added","on"},
      {"Deleted","on"},
      {"Axes","on"},
      {"Left Hull","on"},
      {"Right Hull","on"},
      {"Selected","on"}
    };
 
    return defaults;
  }
 
  // Return information suitable for display in an About dialog box.
  public String getAppletInfo() {
    return "3D Hull Applet v1.13\nWritten by Tim Lambert.";
  }
 
public class Ouvrir extends JFrame implements ActionListener{
 
	  JButton open = new JButton("Selectionner un fichier"); //nouveau bouton open
	  JTextField status = new JTextField("Pas de fichier chargé!"); //nouveau champs de texte
 
	  public Ouvrir() {
	  super("Test d'ouverture d'un JFileChooser"); //titre
	  setSize(450,100); //taille
	  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//fermeture
	  status.setEditable(false);
	  open.addActionListener(this);//ajout d'un actionlistener
	  JPanel pane = new JPanel();
	  BorderLayout bord = new BorderLayout();
	  pane.setLayout(bord);
	  pane.add("North", status);
	  pane.add("Center", open);
	  setContentPane(pane);
	  setVisible(true);
	  }
 
	  public void main(String[] arguments) {
	  try{
	  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
	  }
	  catch (Exception e)
	  {
	  }
	  Ouvrir index = new Ouvrir();
	  }
 
	  public void actionPerformed(ActionEvent evt) {
 
	  }
	  } 
 
 
public static void main(java.lang.String[] args) {
	 Frame frMain = new Frame("Display");
     DisplayT mainApp =  new DisplayT();
     frMain.resize(100,100);
     frMain.show();
     mainApp.init();
     frMain.add("Center",mainApp);
 
 
	   }
 
}
merci d'avance pour l'aide.