日期:2014-05-20  浏览次数:20747 次

一个SWT做的Browser的多线程问题。谢谢
这是一个用SWT做的Browser,现在有一个小问题,就是点击页面上的链接后,会弹出一个IE的窗口和自己做的浏览器窗口,而浏览器窗口页面什么都没有?请教下,怎么解决?
第二个问题,在新线程中,locationText(地址栏),怎么不起作用了?

谢谢哈!!!
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.CloseWindowListener;
import org.eclipse.swt.browser.TitleListener;
import org.eclipse.swt.browser.TitleEvent;
import org.eclipse.swt.browser.VisibilityWindowListener;
import org.eclipse.swt.browser.WindowEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;



public class Browser2 
{
Display display;
private Shell shell;

private Composite com;
private Button forwardButton;
public Button backButton;
public Button stopButton;
public Button refreshButton;

public Text locationText;
public Button goButton;


public Label statusText;
public ProgressBar progressBar;
private Browser browser;

public String url;
public void setUrl(String string)
{
this.url=string;
}
public void createMenuBar(Shell shell)
{

}

public ToolBar createToolBar(Shell shell)
{
ToolBar toolBar=new ToolBar(shell,SWT.None);
ToolItem forwardItem=new ToolItem(toolBar,SWT.None);
forwardItem.setText("前进");
ToolItem backItem=new ToolItem(toolBar,SWT.None);
backItem.setText("后退");
ToolItem stopItem=new ToolItem(toolBar,SWT.None);
stopItem.setText("停止");
ToolItem refreshItem=new ToolItem(toolBar,SWT.None);
refreshItem.setText("刷新");
 
toolBar.pack();
return toolBar;
}

public Composite createAddressBar(Shell shell)
{

Composite com =new Composite(shell,SWT.BORDER);

Label inputLabel=new Label(com,SWT.NONE);
inputLabel.setText("输入网址:");
inputLabel.setBounds(5, 10, 60, 20);

locationText=new Text(com,SWT.BORDER);
locationText.setBounds(70, 10, 300, 20);

goButton = new Button(com, SWT.PUSH);
goButton.setText("进入");
goButton.setBounds(500, 10, 50, 20);
goButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event)
{

Shell shell2 = createShell(display);
Browser browser = createBrowser(shell2);
locationText=locationText;
System.out.println("0010"+locationText.getText());
initialize(display,browser );
browser.setUrl(locationText.getText());


}
});
return com;
}
public Shell createShell(final Display display)
{

Shell shell=new Shell(display);
shell.setLayout(new FormLayout());
createMenuBar(shell);
createToolBar(shell);
Composite com =this.createAddressBar(shell);
com.setBounds(5, 10, 100, 20);
FormData data = new FormData();
data.top= new FormAttachment(shell,20); 
data.left = new FormAttachment(0, 5); 
// data.bottom = new FormAttachment(10, -5); 
data.right = new FormAttachment(100, -5);
com.setLayoutData(data);