Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the code I used to accomplish exactly what you'd like to do, but first let me give you a few tips. </p> <p>If you're in a Java Swing environment, make sure to use the methods in the javax.swing.text.html and javax.swing.text.html.parser packages. Unfortunately, they're mostly intended for use on a JEditorPane, but I'd still strongly recommend that you take a look at these.</p> <p>There's a class in the Java 6 API called HTML.Tag that identifies the HTML start and end tags, which you can then use in order to determine where the links are that you'd like your program to follow.<a href="http://java.sun.com/javase/6/docs/api/javax/swing/text/html/HTML.Tag.html" rel="nofollow noreferrer" title="Link to HTML.Tag in Java API">http://java.sun.com/javase/6/docs/api/javax/swing/text/html/HTML.Tag.html</a></p> <p>When I wrote a program very similar to this, I used 3 main methods: </p> <pre><code>public void handleStartTag(HTML.Tag t, MUtableAttributeSet atts, int pos) public void handleEndTag(HTML.Tag t, int pos) public void handleText(char[] text, int pos) </code></pre> <p>If you need more help on how to write these methods, you can message me, but basically, you are looking for an initial tag and an end tag and then from that you will have identified the url and then you can proceed to the next step, which is following the url.</p> <p>To follow the url, I advise you to use the JEditorPane object. The javax.swing.event.HyperlinkListener interface defines only one method, hyperlinkUpdate(HyperlinkEvent e), which you can pass the url into and then call .setPage(evt.getURL()) on your JEditorPane object. This will then update the pane with the new page and allow you to start the process again.</p> <p>Msg me if you have any probs and please vote this answer!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload