java超链接怎么实现?

来源:百度知道 编辑:UC知道 时间:2024/05/23 10:16:02
不是用HTML。
比如说点击“注册”按键就打开一个预先做好的注册的网页;

对于JEditorPane,JTextPane,JTextArea,JLabel可以使用
setText("<html><A href='http://www.baidu.com'>test</A></html>")
对于JEditorPane使用
setEditorKitForContentType("text/html", new PatchedHTMLEditorKit());
addHyperlinkListener(HyperlinkListener ... );
==================写一个例子~仅供参考====
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class Hyperlink extends JFrame {

public Hyperlink(){
JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setEditable(false);
jEditorPane.setContentType("text/html");
jEditorPane.setText("<html><body><a href=http://www.baidu.com>