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
| import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.awt.event.ActionEvent;
public class fenetre extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
fenetre frame = new fenetre();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public fenetre()
{
String nomSession = System.getProperty("user.home");
File inputFile = new File(nomSession+"/Desktop/test.xlsx");
File outputFile = new File(nomSession+"/Desktop/test.pdf");
setTitle("Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 163);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
System.out.println(inputFile);
System.out.println(outputFile);
JButton btnScript = new JButton("Script");
btnScript.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
Runtime.getRuntime().exec("debut.bat");
System.out.println("Lancement du script");
JOptionPane.showMessageDialog(null, "Lancement du script réussit");
}
catch (IOException e2)
{
e2.printStackTrace();
System.out.println("Erreur du script");
JOptionPane.showMessageDialog(null, "Erreur du lancement du script");
}
}
});
btnScript.setBounds(157, 27, 99, 25);
contentPane.add(btnScript);
JButton btnConvertir = new JButton("Convertir");
btnConvertir.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
try
{
connection.connect();
System.out.println("Convertion réussit");
}
catch (IOException e1)
{
e1.printStackTrace();
System.out.println("Connection refusé");
JOptionPane.showMessageDialog(null, "Echec de la convertion");
try
{
Runtime.getRuntime().exec("fin.bat");
}
catch (IOException e2)
{
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
DocumentConverter PDFconverter = new OpenOfficeDocumentConverter(connection);
PDFconverter.convert(inputFile, outputFile);
connection.disconnect();
}
});
btnConvertir.setBounds(157, 75, 99, 25);
contentPane.add(btnConvertir);
}
} |
Partager