javaSE可以直接编写代码浏览网站吗
就是使用javaSE的技术例如输入:www.youerw.com就可以跳转到百度的网站
请问下SE可以做到吗?跪求代码实现
代码如下,贴出来供和大家一起学习(运行时需要导入swt相关的jar包):
Java code?import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class SWTBrowserTest { public static void main(String args[]) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SWT Browser Test"); shell.setSize(800, 600); final Text text = new Text(shell, SWT.BORDER); text.setBounds(110, 5, 560, 25); Button button = new Button(shell, SWT.BORDER); button.setBounds(680, 5, 100, 25); button.setText("go"); Label label = new Label(shell, SWT.LEFT); label.setText("输入网址 :"); label.setBounds(5, 5, 100, 25); final Browser browser = new Browser(shell, SWT.FILL); browser.setBounds(5, 30, 780, 560); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { String input = text.getText().trim(); if (input.length() == 0) return; if (!input.startsWith("http://")) { input = "http://" + input; text.setText(input); } browser.setUrl(input); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
按钮的事件里加上一句
Java code?12 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://www.youerw.com");