gpt4 book ai didi

java - 小部件已处置

转载 作者:行者123 更新时间:2023-12-01 16:03:07 25 4
gpt4 key购买 nike

大家哀悼

我有一个主屏幕,具有以下键绑定(bind):

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 时,将打开搜索屏幕。我的问题是:第一次打开销售屏幕时,搜索屏幕正常工作,但如果关闭并再次打开销售屏幕,搜索屏幕无法工作,并抛出错误:小部件已处置。错误发生在源代码中的第 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 中关闭窗口的最佳方式?谢谢!

最佳答案

为了解决我的问题,我将进程分成线程。

关于java - 小部件已处置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3336628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com