Process p = null;
try {
p = Runtime.getRuntime().exec("cmd.exe /c start http://www.sohu.com");
}
catch (IOException ex) {
}
try {
p.waitFor();
}
catch (InterruptedException ex1) {
}
try {
p = Runtime.getRuntime().exec("cmd.exe /c start http://www.sohu.com");
}
catch (IOException ex) {
}
try {
p.waitFor();
}
catch (InterruptedException ex1) {
}
解决方案 »
- 微软LiveMeeting中的那种窗体如何实现?
- 出一道看上去几乎不可能实现的题目
- 关于异常与多态性
- CORBA接口的设备专业网管与综合网管,谁是服务端?
- 有无此集合?
- 关于SWT Table 的一个问题
- 用JasperReport输出PDF格式报表出错!
- 新人问题
- 请教Leemaasn,还是关于创建类。 请大家也来看看。
- 怎么将string 和object互相转换!
- 哪里可以下载到jeffheaton的机器人包
- lomboz+jboss+eclipse配置j2ee项目提示Attribute "work-dir" must be declared for element type "web-app".
import java.awt.event.*;
import javax.swing.*;
import java.io.*;class ButtonPanel extends JPanel implements ActionListener
{
public ButtonPanel()
{
yellowButton = new JButton("Yellow");
blueButton = new JButton("Blue");
redButton = new JButton("Red"); add(yellowButton);
add(blueButton);
add(redButton); yellowButton.addActionListener(this);
blueButton.addActionListener(this);
redButton.addActionListener(this);
} public void actionPerformed(ActionEvent evt)
{
Process p = null;
try {
p = Runtime.getRuntime().exec("cmd.exe /c start http://www.sohu.com");
}
catch (IOException ex) {
}
try {
p.waitFor();
}
catch (InterruptedException ex1) {
}
Object source = evt.getSource();
Color color = getBackground();
if (source == yellowButton) color = Color.yellow;
else if (source == blueButton) color = Color.blue;
else if (source == redButton) color = Color.red;
setBackground(color);
repaint();
} private JButton yellowButton;
private JButton blueButton;
private JButton redButton;
}class ButtonFrame extends JFrame
{
public ButtonFrame()
{
setTitle("ButtonTest");
setSize(300,200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}); Container contentPane = getContentPane();
contentPane.add(new ButtonPanel());
}
}public class ButtonTest
{
public static void main(String args[])
{
JFrame frame = new ButtonFrame();
frame.show();
}
}