⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connect.txt

📁 Java实现程序中添加超级链接 方便的进行网站的访问
💻 TXT
字号:
在JAVA应用按钮实现超链接......

button.addActionListener(new ActionListener() {
   public void actionPerformed(final ActionEvent arg0) {
    try {
       
     //Runtime.getRuntime().exec("C:/Program Files/Internet Explorer/IEXPLORE.exe http://www.baidu.com");  //绝对路径
     Runtime.getRuntime().exec("cmd   /c   start   http://jump.qq.com/clienturl_281?ADUIN=0&ADSESSION=0&ADTAG=CLIENT.QQ.1751_LoginWindow.0");
                     button.setText("i love you");
             } catch (Exception ex) {
              System.out.println("error");
              ex.printStackTrace();
  }
   }
  });

******************************************************************************************
对于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>baidu</a></body></html>"); 
jEditorPane.addHyperlinkListener(new HyperlinkListener() { 

public void hyperlinkUpdate(HyperlinkEvent e) { 
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 
try { 
String command = "explorer.exe " 
+ e.getURL().toString(); 
Runtime.getRuntime().exec(command); 
} catch (Exception ex) { 
ex.printStackTrace(); 
System.err.println("connection error"); 
} 
} 

} 

}); 
this.getContentPane().add(jEditorPane); 
this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
} 
public static void main(String[] args) { 
Hyperlink temp = new Hyperlink(); 
temp.setSize(200,200); 
temp.setVisible(true); 
} 

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -