swing gui 打开url 连接的一个方法
来源:互联网 发布:微博域名怎么才正确 编辑:程序博客网 时间:2024/05/29 07:00
// coding
StringBuffer html = new StringBuffer();
private static final String LEGAL_INFORMATION = "Legal_Information";
html.append("<html><head></head>");
html.append("<body style='font-family: Pain; color:#383838; font-size: 8px; font-weight: normal;'>");
html.append(" <a href="+LEGAL_INFORMATION+"> Legal<BR>");
html.append("Information</a>. By use of this system, the user consents to the terms of this Notice.");
html.append("</body></html>");
JEditorPane last = new JEditorPane("text/html", html.toString());
last.setBackground(this.getBackground());
last.setEditable(false);
last.setSelectionColor(this.getBackground());
last.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType().equals(EventType.ENTERED)){
setCursor(new Cursor(Cursor.HAND_CURSOR));
}else{
if(e.getEventType().equals(EventType.EXITED)){
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
if(e.getEventType().equals(EventType.ACTIVATED)){
if (e.getDescription() != null) {
if (LEGAL_INFORMATION.equals(e.getDescription())) {
openURL("http://www.yourCompany.com/legal.html");
}
}
}
}
});
//open url
public static void openURL(String url) {
String errMsg = "Error attempting to launch web browser";
String osName = System.getProperty("os.name");
try {
if(osName.startsWith("Mac OS")) {
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
openURL.invoke(null, new Object[] { url });
} else if(osName.startsWith("Windows")){
Runtime.getRuntime().exec((new StringBuilder()).append("rundll32 url.dll,FileProtocolHandler ").append(url).toString());
} else {
String browsers[] = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
String browser = null;
for(int count = 0; count < browsers.length && browser == null; count++)
if( Runtime.getRuntime().exec( new String[] { "which", browsers[count] }).waitFor() == 0)
browser = browsers[count];
if(browser == null)
throw new Exception("Could not find web browser");
Runtime.getRuntime().exec(new String[] { browser, url});
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, (new StringBuilder()).append(errMsg).append(":/n").append(e.getLocalizedMessage()).toString());
}
}
- swing gui 打开url 连接的一个方法
- GUI Swing 组件常用方法
- swing中添加url连接
- 打开网站Url连接
- 基于Swing的GUI客户端
- 在NetBeans IDE设计一个Swing GUI
- 通过url打开app的方法
- 通过url打开app的方法
- C++打开一个URL
- 基于GUI的AWT,Swing写的一个餐厅点菜系统
- 一个JAVA SWING GUI使用到的open source和commercial tools
- 打开一个进程的方法
- vc 连接 打开url服务器
- Jigloo SWT/Swing GUI Builder 的安装
- Java的GUI发展-AWT/SWT/Swing
- **JAVA** GUI图形界面编程-Swing的使用
- **JAVA** GUI图形界面编程-swing的使用
- 打开MySQL远程连接的方法
- C++中的动态二维数组创建
- [HTML][CSS]同一元素应用多个class的优先级的测试!
- DB2 故障处理的思路及一般问题的解决办法
- 分页查询存储过程[通用]
- 树状目录
- swing gui 打开url 连接的一个方法
- 元数据的由来与定义
- 到底DB2 catalog是什么东西?
- Mysql 常用到的方法汇总
- 对反射的思考——另一种抽象,另一种实现
- 初学struts2编程遇到的问题
- 3GP转换器 http://www.zhuanhuan.com 转换器下载
- 用Java插件在浏览器中运行Java2 Applet
- JRobin简介