java - How can I read html that loads after the rest of the other html? -
ok, sorry question crap. it's hard put question :p
if put word thought dictionary.com or irregular verb pronunciation [thawt] loads after rest of html.
if check code you'll see mean. instead of [thawt] loads [thingk]..
package oepr; import java.awt.eventqueue; import java.awt.gridlayout; import java.awt.toolkit; import javax.swing.jframe; import javax.swing.jbutton; import java.awt.gridbaglayout; import java.awt.gridbagconstraints; import java.awt.datatransfer.clipboard; import java.awt.datatransfer.clipboardowner; import java.awt.datatransfer.stringselection; import java.awt.datatransfer.transferable; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.io.bufferedreader; import java.io.inputstreamreader; import java.net.url; import java.net.urlconnection; import java.util.regex.matcher; import java.util.regex.pattern; import javax.swing.grouplayout; import javax.swing.grouplayout.alignment; import javax.swing.layoutstyle.componentplacement; import javax.swing.jtextfield; public class oepr { private jframe frame; private jtextfield txtword; private jtextfield textpron; /** * launch application. */ private static string wordurl; private static string line; private int linenum; private static int findingfirst = 0; private static string pron; stringselection testcopy; public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { try { oepr window = new oepr(); window.frame.setvisible(true); } catch (exception e) { e.printstacktrace(); } } }); } /** * create application. */ public oepr() { initialize(); setvars(); } public void setvars() { oepr.wordurl = "http://dictionary.reference.com/browse/" + txtword.gettext(); } public void geturl(string[] args) throws exception { // set url url url = new url(wordurl); urlconnection spoof = url.openconnection(); // spoof connection web browser spoof.setrequestproperty("user-agent", "mozilla/4.0 (compatible; msie 5.5; windows nt 5.0; h010818)"); bufferedreader in = new bufferedreader(new inputstreamreader( spoof.getinputstream())); string uline = ""; // loop through every line in source while ((uline = in.readline()) != null) { system.out.println(uline); line = uline; linecheck(); } // system.out.println(oepr.line); } private void linecheck() { pattern pattern = pattern.compile("<!-- google_ad_section_start -->"); pattern pattern2 = pattern.compile("\\[.*?]"); matcher matcher = pattern.matcher(oepr.line); if (matcher.find()) { findingfirst++; // if(findingfirst==2){ string nohtml = line.replaceall("\\<.*?>", ""); matcher matcher2 = pattern2.matcher(nohtml); if (matcher2.find()) { pron = nohtml.replaceall("(^.*(?=\\[))|((?<=\\]).*$)", ""); // system.out.println(pron); textpron.settext(pron); } // } // system.out.println(matcher.group(0)); //prints /{item}/ } else { // system.out.println("match not found"); } } public void setclipboardcontents(string astring) { testcopy = new stringselection(pron); toolkit.getdefaulttoolkit().getsystemclipboard() .setcontents(testcopy, null); } /** * initialize contents of frame. */ private void initialize() { frame = new jframe(); frame.setalwaysontop(true); frame.setresizable(false); frame.setsize(210, 100); jbutton btngo = new jbutton("go!"); btngo.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { // execute when button pressed try { setvars(); oepr.findingfirst = 0; geturl(null); } catch (exception e1) { // todo auto-generated catch block e1.printstacktrace(); } } }); jbutton btncopy = new jbutton("copy!"); btncopy.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { // execute when button pressed try { setclipboardcontents(null); } catch (exception e1) { // todo auto-generated catch block e1.printstacktrace(); } } }); txtword = new jtextfield(); txtword.settext("thought"); txtword.setcolumns(10); textpron = new jtextfield(); textpron.setcolumns(10); grouplayout grouplayout = new grouplayout(frame.getcontentpane()); grouplayout .sethorizontalgroup(grouplayout .createparallelgroup(alignment.leading) .addgroup( alignment.trailing, grouplayout .createsequentialgroup() .addgroup( grouplayout .createparallelgroup( alignment.leading) .addgroup( grouplayout .createsequentialgroup() .addcontainergap( grouplayout.default_size, short.max_value) .addcomponent( txtword, grouplayout.preferred_size, grouplayout.default_size, grouplayout.preferred_size) .addpreferredgap( componentplacement.related)) .addgroup( grouplayout .createsequentialgroup() .addcontainergap() .addcomponent( textpron, grouplayout.preferred_size, grouplayout.default_size, grouplayout.preferred_size) .addpreferredgap( componentplacement.related))) .addgroup( grouplayout .createparallelgroup( alignment.leading) .addcomponent(btngo) .addcomponent(btncopy)) .addcontainergap())); grouplayout .setverticalgroup(grouplayout .createparallelgroup(alignment.leading) .addgroup( grouplayout .createsequentialgroup() .addcontainergap() .addgroup( grouplayout .createparallelgroup( alignment.baseline) .addcomponent(btngo) .addcomponent( txtword, grouplayout.preferred_size, grouplayout.default_size, grouplayout.preferred_size)) .addpreferredgap( componentplacement.related) .addgroup( grouplayout .createparallelgroup( alignment.baseline) .addcomponent(btncopy) .addcomponent( textpron, grouplayout.preferred_size, grouplayout.default_size, grouplayout.preferred_size)) .addcontainergap( grouplayout.default_size, short.max_value))); frame.getcontentpane().setlayout(grouplayout); } }
Comments
Post a Comment