将以下代码保存为 Test.java 即可运行(界面挫了点,不过核心功能都有,你可以自己拿回去改改界面就可以了)
package com;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Test extends JFrame{
public static void main(String args[]){
new Test();
}
JTextField ieField;
JButton button;
public Test(){
super("单击按钮打开一个网页");
ieField = new JTextField("
www.sina.com",30);
button = new JButton("打开 IE 网页");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
try{
Process process = Runtime.getRuntime().exec("cmd.exe /C start iexplore " + ieField.getText());
}catch(Exception e){
e.printStackTrace();
}
}
});
this.getContentPane().setLayout( new BorderLayout());
this.getContentPane().add(ieField,BorderLayout.CENTER);
this.getContentPane().add(button,BorderLayout.SOUTH);
this.setSize(600,200);
this.setVisible(true);
}
}
散分吧 赚点小分真不容易....