java swt文件夹浏览器_java swt 打开浏览器

下面是本人做的小例子使用的是swt技术,这个例子没有业务逻辑主要是为了说明swt打开浏览器的实现,本人加入了线程的控制提交程序运行速度。小弟初来乍到,如果下面的小例子有可以改进的地方希望大侠不惜赐教:

代码如下:

import java.io.IOException;

import org.eclipse.swt.SWT;

import org.eclipse.swt.events.SelectionAdapter;

import org.eclipse.swt.events.SelectionEvent;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

public class Test extends Thread {

public static void main(String[] args) throws Exception {

new Test().start();

}

public void run(){

goIntnet();

}

public void goIntnet(){

Display display = new Display();

Shell shell = new Shell(display);

shell.setText("打开浏览器");

shell.setBounds(300, 100, 600, 400);

Button goIntenet = new Button(shell, SWT.NONE);

goIntenet.setText("打开浏览器");

goIntenet.setBounds(150, 80, 300, 200);

goIntenet.addSelectionListener(new SelectionAdapter() {

@Override

public void widgetSelected(SelectionEvent e){

try {

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandlerhttp://localhost:8080/");

} catch (IOException e1) {

e1.printStackTrace();

}

}

});

shell.open();

while(!shell.isDisposed()){

if(!display.readAndDispatch()){

display.sleep();

}

}

}

}

运行结果如下图所示:

2fb92f161aa4a0f7448b8dfd1d0d65c5.png

点击按钮,可以成功打开浏览器窗口如下图所示:

3845c5e330ff7bfeb2cb3a189c29e39f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值