|
rq: We prefer to use WEB START
technology instead of APPLET. Java Web Start provides a platform-independent, secure, and robust deployment technology. It enables developers to deploy full-featured applications to end-users by making the applications available on a standard web server. With any web browser, end-users can launch the applications and be confident they always have the most-recent version :
- It use the native JVE instead of the JVE of the browser.
- It is easy to use with NETBEANS and trully simplify the librairies distribution and signature by certificate.
- It seems to do what we really wanted to do using the APPLET.
- It was advised to us by the JAVA computers scientist of the LPSC laboratory.
1 Introduction
An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page.
You will find here some notes about the Netbeans tutorial.
2 Is-it really working ?
... sometime yes. Into NETBEANS do:
- Open a new project called ``JavaApplication1''
- Create a new JAppletForm file (from the Swing GUI Forms cathégory and call it NewJApplet.java
- Add a color Chooser component to the pannel so as to have this code:
public class NewJApplet extends javax.swing.JApplet {
/** Initializes the applet NewJApplet */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void initComponents() {
jColorChooser1 = new javax.swing.JColorChooser();
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jColorChooser1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jColorChooser1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
}
private javax.swing.JColorChooser jColorChooser1;
}
- Test this selected file with
Maj-F6
- Build the dist/JavaApplication1.jar with
F11
Outside of NETBEANS:
- Copy the JAR archive int /htdocs
- Create the applet1.html file:
<applet
code=NewJApplet.class
archive="JavaApplication1.jar">
width=350 height=200
</applet>
- Now you should be able to load at this
URL.
3 Signing the JAR file
Please try this second applet (doing like above) so as to test:
- That your browser ask you for accepting our certificat.
- That you cannot write to a file if you refuse it
- That you can write to a file by accepting it
- testing IO
import java.io.*;
public class NewJApplet extends javax.swing.JApplet {
/** Initializes the applet NewJApplet */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void initComponents() {
jToggleButton1 = new javax.swing.JToggleButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jToggleButton1.setText("test");
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToggleButton1)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 323,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(206, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jToggleButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 155,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(151, Short.MAX_VALUE))
);
}
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
jTextArea1.append("testing...");
BufferedWriter fichier = new BufferedWriter(new FileWriter("/tmp/tata.log"));
fichier.write("bonjour tout le monde");
fichier.newLine();
fichier.close();
} catch (Exception e){
System.out.println(e.toString());
jTextArea1.append(e.toString());
}
jTextArea1.append("done");
}
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JToggleButton jToggleButton1;
}
keytool is delivered with Sun's development kit.
$ keytool -genkey -keyalg rsa -alias yourkey
Follow the instructions and type in all needed information.
- Now we make the certificate:
$ keytool -export -alias yourkey -file yourcert.crt
- Now we have to sign the applet:
$ jarsigner yourapplet.jar yourkey
|