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

SWT中的问题,先谢谢了。祝大家情人节快乐!
这是个很简单浏览器,当我在输入框输入个网址后,按下“进入”,却没有什么反应。请教下问题出在哪里?
谢谢了。
问题2,在SWT中,shell,browser 这些赋值弄的很头大,请教下这个问题
问题3,当我从浏览器中,点击链接,弹出了第二个页面。可当我关闭第一个页面时,第二个也会关闭,请教下,该怎么解决?

谢谢了!!!祝大家都情人节快乐。。。

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
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 Browser1 
{
public Display display;
public Shell shell;

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

public Text locationText;
public Button goButton;


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

public void createMenuBar(Shell shell)
{

}
public void 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();
}

public Composite createAddressBar(Shell shell)
{
System.out.println("1221"+shell.getText());
Composite com =new Composite(shell,SWT.BORDER);

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

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

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

 
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.right = new FormAttachment(100, -5);
com.setLayoutData(data);
return shell;
}
public void createBrowser(final Display display,Browser browser )
{
 
Shell shell=this.createShell(display);
FormData formData=new FormData();  
 
  formData.top= new FormAttachment(com,50);