how to open broswser in Swing
来源:互联网 发布:诺瓦刷屏软件下载 编辑:程序博客网 时间:2024/06/02 17:50
package com.sanminasci.scion.spc.client.util;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
*/
public class OpenBrowser {
public static void openURL(String url) {
String osName = System.getProperty("os.name");
try {
if (osName.startsWith("Windows"))
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
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];
Runtime.getRuntime().exec(new String[] { browser, url });
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error in opening browser"+ ":/n" + e.getLocalizedMessage());
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
final JTextField url = new JTextField(20);
JButton button = new JButton("Open Browser");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
OpenBrowser.openURL(url.getText().trim());
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.add(new JLabel("URL:"));
panel.add(url);
panel.add(button);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
- how to open broswser in Swing
- How to Use HTML in Swing Components
- How to open PDF files in sharepoint
- How to Open a Text File in VB .NET
- How To Open Block Material in SAP MM?
- How To Open An URL In Android’s Web Browser
- 1. How to open items in other iOS Apps
- How to open a popup window in infopath
- [Python] How to Open Zip File in Host Location.
- How to open bug
- How to Use Swing Timers
- How to open a JFrame
- How to open a file
- How to open UITextView web links in a UIWebView instead of Safari?
- How to change the name in open with list / File association.
- How to open application with notification from LocalNotifications plugin in PhoneGap
- How to open another page in HTML5 Builder Server Mobile Application
- How to search a table in a store proc and open the store proc
- jQuery性能优化
- Linux 使用救援模式备份数据
- cgic基本知识
- 有关Linux终端
- X-cs模式
- how to open broswser in Swing
- 获取积分
- servlet下载文件
- 眼过千遍不如手过一遍——静态链接库的编写
- AJAX原始写法
- jfreechart---paint(Graphics g) :g.drawImage(bufferImage, 0, 0, null);
- 程序员的命运要掌握在自己手中
- Visual Studio.net 2010 Windows Service 开发,安装与调试
- svn权限配置