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
|
public class FileAfficher extends JFrame {
private JTextPane texte;
private boolean texteModifie = false;
private String reponse; private HTMLDocument doc;
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
new FileAfficher();
}
FileAfficher() {
super("File Printer");
setSize(new Dimension(800, 800));
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
texte = new JTextPane();
texte.setContentType("text/html" );
HTMLEditorKit k = new HTMLEditorKit();
//L'unité de base de la structure est un Element, qui a un ensemble d'attributs.
//Les éléments st de natures différentes suivant qu'on a affaire un texte HTML : html, body, p, content, etc...
doc = (HTMLDocument)k.createDefaultDocument();
texte.setEditorKit(k);
texte.setDocument(doc);
Style defaut = texte.getStyle("default");
Style as = texte.addStyle("stylePerso",defaut);
StyleConstants.setFontFamily(as, "Monospaced");
StyleConstants.setFontSize(as, 20);
StyleConstants.setAlignment(as, 1);
StyledDocument docStyled = texte.getStyledDocument();
texte.setBackground(Color.WHITE);
texte.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent evt) {
texteModifie = true;
}
});
getContentPane().add(new JScrollPane(texte));
setJMenuBar(barreMenus());
setVisible(true);
}
private JMenuBar barreMenus() {
[.....]
menu.addSeparator();
JMenuItem information = new JMenuItem("Information");
menu.add(information);
information.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String reponse = JOptionPane.showInputDialog("Nom du centre hospitalier?");
/*
* String nomCentre= JOptionPane.showInputDialog("Nom du centre hospitalier: ");
* String idCentre= JOptionPane.showInputDialog("Identifiant du centre hospitalier: ");
* String nomPreleveur= JOptionPane.showInputDialog("Préleveur: ");
* String datePrelev=JOptionPane.showInputDialog("Date de prélèvement:");
* String heureArrivee=JOptionPane.showInputDialog("Heure d'arrivée:");
* String heureDepart=JOptionPane.showInputDialog("Heure de départ:");
* int numeroPage= JOptionPane.showInputDialog("Numero de fiche:");
*/
try {
FicheRecapi(reponse);
/*
* Fiche(nomCentr,nomPreleveur,datePrelev,heureArrivee,heureDepart);
*/
texteModifie =true;
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
return barre;
}
private void FicheRecapi(String reponse) throws IOException{
String filename ="/home/fripette/workspace/FilePrinter/finFicheRecap.html";
texte.setText(filename); |
Partager