欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

超级链接文本框,,import java.

来源: javaer 分享于  点击 35262 次 点评:29

超级链接文本框,,import java.


import java.awt.*;import javax.swing.*;import javax.swing.event.*;public class Test extends JFrame {    private static final long serialVersionUID = 1L;    private JEditorPane jEditorPane = new JEditorPane();    public Test() {        super("超级链接文本框");        this.setLayout(new BorderLayout());        jEditorPane.setEditable(false);        jEditorPane.setContentType("text/html");        jEditorPane                .setText("<html><body><a href=http://www.baidu.com>百度</a></body></html>");        jEditorPane.addHyperlinkListener(new HyperlinkListener() {            public void hyperlinkUpdate(HyperlinkEvent e) {                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {                    try {                        Runtime.getRuntime().exec(new String[]{"C:\\\\Program Files\\\\Internet Explorer\\\\iexplore.exe",e.getURL().toString()});                    } catch (Exception ex) {                        ex.printStackTrace();                        System.err.println("connection error");                    }                }            }        });        this.add(jEditorPane);        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        this.setSize(100, 80);        this.setLocation(100, 200);        this.setVisible(true);    }    public static void main(String[] args) {        new Test();    }}//该片段来自于http://byrx.net
相关栏目:

用户点评