Save a http link in word document with java BufferedWriter -
i want save http link in word document using java application (file.doc) .i succesfully write link word document using bufferedwriter class link in word document simple line of text . if press enter button on document word turns http link , that's want java application , save http format
here code :
import java.awt.borderlayout; import java.awt.dimension; import java.awt.eventqueue; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.border.emptyborder; import javax.swing.jfilechooser; import javax.swing.jlabel; import javax.swing.jbutton; import javax.swing.joptionpane; import javax.swing.jtextpane; import java.awt.font; import java.awt.event.actionlistener; import java.awt.event.actionevent; import java.io.bufferedwriter; import java.io.file; import java.io.filewriter; import javax.swing.jtextfield; import java.awt.toolkit; import javax.swing.imageicon; import java.awt.event.mouseadapter; import java.awt.event.mouseevent; public class save_file extends jframe { private jpanel contentpane; public static jtextfield textfield; jfilechooser chooser; file file; public static filewriter fw; public static bufferedwriter output; string the_past; /** * launch application. */ public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { try { save_file frame = new save_file(); frame.setvisible(true); } catch (exception e) { e.printstacktrace(); } } }); } /** * create frame. */ public save_file() { setresizable(false); seticonimage(toolkit.getdefaulttoolkit().getimage(save_file.class.getresource("/buttons/logoicon.png"))); settitle("saving file"); this.setsize(435, 300); dimension dim = toolkit.getdefaulttoolkit().getscreensize(); this.setlocation(dim.width/2-this.getsize().width/2, dim.height/2-this.getsize().height/2); setdefaultcloseoperation(jframe.exit_on_close); // setbounds(100, 100, 435, 300); contentpane = new jpanel(); contentpane.setborder(new emptyborder(5, 5, 5, 5)); setcontentpane(contentpane); contentpane.setlayout(null); jlabel lblnewlabel = new jlabel("select file :"); lblnewlabel.setfont(new font("tahoma", font.bold, 13)); lblnewlabel.setbounds(12, 13, 152, 25); contentpane.add(lblnewlabel); jbutton btnnewbutton = new jbutton(""); btnnewbutton.seticon(new imageicon(save_file.class.getresource("/buttons/loaddisk (2).gif"))); btnnewbutton.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { try{ output = new bufferedwriter(fw); output.write(textfield.gettext()+"\n"); output.write(" "); joptionpane.showmessagedialog(null, "saving succes", "save", joptionpane.information_message); //textfield.settext(""); output.write("\r"); output.flush(); output.close(); } catch(exception io){ joptionpane.showmessagedialog(null, "saving failed", "error", joptionpane.error_message); } } }); btnnewbutton.setbounds(142, 211, 32, 32); contentpane.add(btnnewbutton); jlabel lbllink = new jlabel("link "); lbllink.settooltiptext("just click once past"); lbllink.setfont(new font("tahoma", font.bold, 13)); lbllink.setbounds(12, 107, 97, 25); contentpane.add(lbllink); textfield = new jtextfield(); textfield.settooltiptext("just click once past"); textfield.addmouselistener(new mouseadapter() { @override public void mouseclicked(mouseevent arg0) { the_past= textfield.gettext(); if (the_past.isempty()){ textfield.paste(); } //else //textfield.settext(""); } }); textfield.setcolumns(10); textfield.setbounds(12, 154, 393, 33); contentpane.add(textfield); jbutton btnopenfile = new jbutton("open file"); btnopenfile.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { try{ chooser = new jfilechooser(); int retval = chooser.showopendialog(save_file.this); if (retval == jfilechooser.approve_option) { //... user selected file, it, use it. file file = chooser.getselectedfile(); system.out.println("file equals"+file); fw = new filewriter(file, true); } } catch(exception io){ } } }); btnopenfile.setbounds(12, 53, 97, 25); contentpane.add(btnopenfile); jbutton button = new jbutton(""); button.seticon(new imageicon(save_file.class.getresource("/buttons/cc.jpg.png"))); button.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { system.exit(0); } }); button.setbounds(243, 211, 35, 35); contentpane.add(button); } }
no, not doing that.
you writting text (ascii or utf) file string use, , assign .doc extension file. a .doc extension not make file word document. ms word can read automatically text files , show it, not writting (i repeat) word file.
search api allows manipulating/creating word files (i think apache has 1 of them).
Comments
Post a Comment