看看这个,这问题网上好找,我就来个回答:lol
其实就是用Runtime.getRuntime().exec()来实现的。[code]import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test_82 extends JFrame{
public Test_82(){
JButton button=new JButton("跳转");
button.addActionListener(getActionListener());
add(button);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200,200);
setVisible(true);
}
public ActionListener getActionListener(){
return new ActionListener(){
public void actionPerformed(ActionEvent e) {
try {
//主要看这里
Runtime.getRuntime().exec("explorer.exe http://bbs.itheima.com/thread-935-1-1.html");
} catch (IOException e1) {
e1.printStackTrace();
}
}
};
}
public static void main(String args[]){
new Test_82();
}
}[/code] |