谁让我解决一下窗口问题,代码在下面

ljb397635772 2009-07-01 11:56:46
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;




public class Mb {
private static Display display;
private static Shell shell;
private static Composite composite;
public static void init(){
display = new Display();
shell = new Shell(display,SWT.SHELL_TRIM);
shell.setSize(215, 550);
shell.open();

}
public static void init_1(){
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

public static void 上(){
init();
Label label = new Label(shell,SWT.NO);
label.setText("aaa");
label.setBounds(0, 0, 100, 20);
init_1();
}
public static void 下(){
init();
Label label_1 = new Label(shell,SWT.NO);
label_1.setText("bb");
label_1.setBounds(0, 30, 100, 20);
init_1();
}
}
这是我写的方法

public class mainT {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub


}

}
这是我写的主类;
问题是这样的 。我调用Mb.上();和Mb.下();想在同一个窗口上显示出来我写的两个方法,但是现在我写的两个方法中.调用这两个方法的时候,必须一个关闭一个窗口后才能显示第二个窗口,而不是在同一个窗口上显示.
我的问题要是解决了.我会把分马上就给.因为我在线等。
...全文
66 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chentao19860501 2009-07-16
  • 打赏
  • 举报
回复
luguo
net_yuhai 2009-07-16
  • 打赏
  • 举报
回复
Thread
biosli 2009-07-14
  • 打赏
  • 举报
回复
你init_1如果按键没按抬起是类似于死循环的。
你需要一个异步消息处理来完成你的工作。
qiang_0629 2009-07-14
  • 打赏
  • 举报
回复
恩,弄个先程就能同时运行2个方法了
laorer 2009-07-01
  • 打赏
  • 举报
回复
那你把打开窗体的代码放到 thread 中吧, 因为你的代码是顺序运行的, 如果上一个没关,后面肯定没有运行到

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧