1. 程式人生 > >SWT之四:多窗體

SWT之四:多窗體

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Display display = new Display();
  final Shell parent = new Shell(display, SWT.SHELL_TRIM);
  parent.setText("多視窗示例");
  
  parent.setSize(300, 200);
  //設定父視窗圖示
  parent.setImage(new Image(display, "E:\\Study\\SWT\\code\\SWTStudy\\src\\SWT\\/ico/firsteps48.gif"));
  Button addShell = new Button(parent, SWT.CENTER);
  addShell.setText("建立子視窗");
  //註冊按鈕單擊事件
  addShell.addSelectionListener(new SelectionListener(){
   
   @Override
   public void widgetSelected(SelectionEvent e) {
    // TODO Auto-generated method stub
    //當單擊時建立子視窗
    createChildrenShell(parent, "子視窗");
   }
   
   @Override
   public void widgetDefaultSelected(SelectionEvent e) {
    // TODO Auto-generated method stub
    
   }
  });
  
  addShell.pack();
  
  parent.open();
  
  while (!parent.isDisposed())
  {
   if (!display.readAndDispatch())
   {
    display.sleep();
   }
  }
  
  display.dispose();
  
 }