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
| public class Remplissage extends javax.swing.JFrame {
static Element racine;
static org.jdom2.Document document1;
/** Creates new form Remplissage */
public Remplissage() {
initComponents();
this.setLocationRelativeTo(null);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Element a = new Element("a") {};
Element addContent = racine.addContent(a);
Attribute e11 =new Attribute("e1",e1.getText());
a.setAttribute(e11);
Attribute e22 =new Attribute("e2",e2.getText());
a.setAttribute(e22);
Attribute e33 =new Attribute("e3",e3.getText());
a.setAttribute(e33);
Attribute e44 =new Attribute("e4",e4.getText());
a.setAttribute(e44);
Attribute e55 =new Attribute("e5",e5.getText());
a.setAttribute(e55);
Attribute e66 =new Attribute("e6",e6.getText());
a.setAttribute(e66);
Attribute e77 =new Attribute("e7",e7.getText());
a.setAttribute(e77);
Attribute e88 =new Attribute("e8",e8.getText());
a.setAttribute(e88);
Attribute e99 =new Attribute("e9",e9.getText());
a.setAttribute(e99);
Attribute e100 =new Attribute("e10",e10.getText());
a.setAttribute(e100);
document1.getRootElement().getChild("tete").addContent(a);
enregistre("src/XML/"+a+".xml");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see <a href="http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html" target="_blank">http://download.oracle.com/javase/tu...feel/plaf.html</a>
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Remplissage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Remplissage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Remplissage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Remplissage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Remplissage().setVisible(true);
}
});
}
static void enregistre(String fichier)
{
try
{
//On utilise ici un affichage classique avec getPrettyFormat()
XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
//Remarquez qu'il suffit simplement de créer une instance de FileOutputStream
//avec en argument le nom du fichier pour effectuer la sérialisation.
sortie.output(document1, new FileOutputStream(fichier));
}
catch (java.io.IOException e){}
} |
Partager