import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.*;
public class TestFrame {
public static String url="about:blank";//默认为空白页
public static String cmd = "rundll32 url.dll,FileProtocolHandler ";
public static void main(String[] args) {
JFrame mainFrame=new JFrame("JavaFrame");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setSize(300, 70);
JLabel jLabel1=new JLabel("网址:");
final JTextField jTextField=new JTextField();
JButton jButton1=new JButton("确定");
mainFrame.getContentPane().add(jLabel1,BorderLayout.WEST);
mainFrame.getContentPane().add(jTextField,BorderLayout.CENTER);
mainFrame.getContentPane().add(jButton1,BorderLayout.EAST);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (jTextField.getText()!=null&&!jTextField.getText().trim().equals("")) {
url=jTextField.getText().trim();
}
try {
Runtime.getRuntime().exec(cmd+url);
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}
}
system("你的网址")