It depends.
I did that once on a scrolling ticker app by pre-generating an image of the text, and calculating what pixel ranges in the image corresponded to the link. Then when I got a mouse click I figured out the current relative position of the image and the position of the mouse click over that image.
You could just use a button.
As I understand it some of the more advanced Swing stuff lets you have hypertext inside of JTextAreas, but I don't know about the details. Ask on a Swing forum.
In AWT text widgets have a getCaretPosition method that you can use to see where the user clicked, perhaps.
In any event, in applets, you can do getAppletContext().showDocument(URL) to go to other pages.
Use a simple JLabel and showDocument:
import java.applet.AppletContext;
import java.net.URL;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HyperlinkApplet extends JApplet {
JLabel jLabel = null;
URL url = null;
AppletContext ac = null;
public HyperlinkApplet() {
try {
jLabel = new JLabel("<html><u>Hyperlink to Java</u></html>");
url = new URL("http://java.sun.com/");
jLabel.setForeground(Color.blue);
jLabel.setToolTipText(url.toString());
jLabel.setHorizontalAlignment(SwingConstants.CENTER);
jLabel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(MouseEvent e) {
jLabel_mouseEntered(e);
}
public void mouseExited(MouseEvent e) {
jLabel_mouseExited(e);
}
public void mouseClicked(MouseEvent e) {
jLabel_mouseClicked(e);
}
});
this.getContentPane().add(jLabel, BorderLayout.CENTER);
}
catch(Exception e) {
e.printStackTrace();
}
}
public void init() {
try {
this.setSize(new Dimension(100,800));
ac = this.getAppletContext();
}
catch(Exception e) {
e.printStackTrace();
}
}
void jLabel_mouseEntered(MouseEvent e) {
jLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
void jLabel_mouseExited(MouseEvent e) {
jLabel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
void jLabel_mouseClicked(MouseEvent e) {
ac.showDocument(url, "_blank");
}
}