2010-07-26 65 views
0

好莫寧大家小部件配置

我有一個主屏,具有如下鍵綁定:

shell.getDisplay().addFilter(SWT.KeyUp, new Listener() { 
    @Override 
    public void handleEvent(Event event) { 
     switch (event.keyCode) { 
     case SWT.ESC: 
      shell.close(); 
      break; 
     case SWT.F12: 
      display.syncExec(new Runnable() { 
       @Override 
       public void run() { 
       new Venda(shell); 
       } 
      });     
      break;     
     default: 
      break; 
     }    
    } 
}); 

當推F12,搜索的屏幕被打開。銷售屏幕的構造商:

public Venda(Shell parent) { 
     super(parent); 
     this.shell = new Shell(getParent(),SWT.APPLICATION_MODAL); 
     this.display = getParent().getDisplay(); 
     this.shell.setMaximized(true); 
     this.shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN)); 
     this.fontText = new Font(shell.getDisplay(), new FontData("Arial", 28, SWT.NORMAL)); 
     this.fontLabel = new Font(shell.getDisplay(), new FontData("Arial", 13, SWT.NORMAL)); 
     this.shell.setText("Cupom Fiscal - Venda Produto"); 
     this.criaCampos(); 
     this.configuraTeclaAtalho(); 
     this.shell.open(); 
     while (!display.isDisposed()) { 
      if (!display.isDisposed() && !display.readAndDispatch()) { 
       display.sleep(); 
      } 
     } 
    } 

當在銷售屏幕上按下F3時,搜索屏幕打開。我的問題是:第一次打開銷售屏幕時,搜索屏幕正常工作,但是如果銷售屏幕關閉並再次打開,搜索屏幕沒有工作,投射錯誤:處理Widget。 錯誤發生在第02行,源代碼如下。 變量「abreFechaCaixa」驗證是否應打開銷售屏幕。

if(!abreFechaCaixa){ 
     MessageBox msg = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO); 
     msg.setMessage("Caixa Fechado, deseja abrir?"); 
    msg.setText(shell.getText()); 
    if(msg.open() == SWT.YES){ 
     abreCaixa(); 
    } 
    } 
if(abreFechaCaixa){ 
    display.syncExec(new Runnable() { 
     @Override 
    public void run() { 
       new Consulta(shell,"Cupom Fiscal - Consulta Produto"); 
    } 
    }); 
} 

構造的搜索屏幕:

public Consulta(Shell parent) { 
       super(parent); 
     this.shell = new Shell(parent, SWT.APPLICATION_MODAL); 
     this.display = getParent().getDisplay(); 
     this.shell.setText(tituloTela); 
     this.shell.setLayout(new GridLayout(1, false)); 
     this.fontText = new Font(shell.getDisplay(), new FontData("Arial", 28, SWT.NORMAL)); 
     this.fontLabel = new Font(shell.getDisplay(), new FontData("Arial", 13, SWT.NORMAL)); 
     this.criaCampos(); 
     this.shell.pack(); 
     this.centralizaTela(); 
     this.shell.open(); 
     while (!shell.isDisposed()) { 
      if (!display.isDisposed() && !display.readAndDispatch()) { 
       display.sleep(); 
      } 
     } 
    } 

你能幫我解決這個問題? 或者顯示關閉SWT窗口的最佳方法? 謝謝!

回答

0

我認爲你需要添加「display.dispose();」在while循環for!shell.isDisposed()之後。如下所示:

while (!shell.isDisposed()) { 
    if (!display.readAndDispatch()){ 
     display.sleep(); 
    } 
    } 
display.dispose(); 
1

要解決我的問題,我在線程中分離了進程。

0

你並不需要在Consultawhile循環,爲ShellVenda一個孩子。這意味着子shell的顯示對象與其父項相同,在您的施工中,在此顯示屏上運行readAndDispatch()因此需要處理兩次。