Esportare Applet

La funzione File > Export trasforma uno sketch in una forma eseguibile all’interno di un browser web. Quando il codice viene esportato da Processing viene prima convertito in codice Java e poi compilato come applet Java.

Quando si esporta un progetto un certo numero di file verranno scritti in una cartella di nome applet creata all’interno della cartella dello sketch.

Tutti i file presenti nella cartella dello sketch verranno esportati come un singolo file JAR con lo stesso nome dello sketch. Per esempio, se lo sketch si chiama Sketch_123, il file esportato si chiamerà Sketch_123.jar.

La cartella applet contiene i seguenti file:

index.html

Il file HTML con l’applet incorporata e i collegamenti al codice sorgente e alla homepage di Processing. Con un doppio clic il file si aprirà nel browser web di default.

Sketch_123.jar

L’archivio Java che contiene tutti i file necessari per l’esecuzione dello sketch. Contiene le classi di Processing, le classi dello sketch, e tutti i file multimediali nella cartella data: immagini, caratteri e suoni.

Sketch_123.java

Il file JAVA generato dal pre-processore a partire dal file PDE. Questo è il file che viene compilato in Applet dal compilatore Java utilizzato da Processing.

Sketch_123.pde

Il file sorgente originale. It is linked from the index.html file.

loading.gif

An image file displayed while the program is loading in a Web browser.

Every time a sketch is exported, the contents of the “applet” folder are deleted and the files are written from scratch. Any changes previously made to the “index.html” file are lost. To customize the HTML that’s included when an applet is exported, copy the applet.html file from Processing → lib → export to the root of your sketch folder.

Media files not needed for the applet should be deleted from the data folder before exporting to keep the file size small. For example, if there are unused images in the “data” folder, they will be added to the JAR file, thus needlessly increasing its size.

When exporting an applet, a description can be included on the default HTML page that’s created. Processing will include everything from the first instance of /** to a closing */ as a javadoc comment. So you can add this to your sketch:

/**
* You can’t rock Processing like I can rock Processing.
*/

and that text would automatically be embedded in the exported html page. Like a javadoc comment, the text can (and should) be any valid html since it will be embedded directly in the page. Asterisks at the left of each line will be removed.


Restrizioni di sicurezza


Applets running inside a web browser have several security restrictions, in order to protect web users. For instance, an applet cannot read files from the local disk or connect to servers other than the server from which it came. To avoid these restrictions, it’s possible to “sign” an applet. In a signed applet, a dialog box will appear to ask the user whether they trust you as the provider of the applet, and if it’s ok for the applet to perform actions that might be a security risk. More information can be found in Sun’s documentation.