Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
import java.io.*;
import java.awt.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class myPan extends JPanel implements HyperlinkListener {
protected JEditorPane html;
URL url;
public myPan() {
setLayout(new BorderLayout());
html=new JEditorPane("text/html","");
html.setText("<html><head></head><body><a href=[URL unfurl="true"]http://www.yahoo.com>click[/URL] to go to yahoo</a><li>Hello</li></body></html>");
html.setEditable(false);
html.addHyperlinkListener(this);
JScrollPane scroller = new JScrollPane();
JViewport vp = scroller.getViewport();
vp.add(html);
vp.setBackingStoreEnabled(true);
add(scroller, BorderLayout.CENTER);
}
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
linkActivated(e.getURL());
}
}
protected void linkActivated(URL u) {
Cursor c = html.getCursor();
Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
html.setCursor(waitCursor);
SwingUtilities.invokeLater(new PageLoader(u, c));
}
class PageLoader implements Runnable {
URL url;
Cursor cursor;
PageLoader(URL u, Cursor c) {
url = u;
cursor = c;
}
public void run() {
if (url == null) {
html.setCursor(cursor);
Container parent = html.getParent();
parent.repaint();
} else {
Document doc = html.getDocument();
try {
html.setPage(url);
} catch (IOException ioe) {
html.setDocument(doc);
getToolkit().beep();
} finally {
url = null;
SwingUtilities.invokeLater(this);
}
}
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("Roadster");
myPan panel = new myPan();
frame.getContentPane().add(panel);
frame.setSize(500, 300);
frame.setVisible(true);
}
}
/code]