SWT筆記三,創建多個窗口

代碼如下,熟悉API和概念:
package com.layotech.www.study;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MultiShell {
public static void main(String[] args) {
Display display = new Display();
final Shell parent = new Shell(display,SWT.SHELL_TRIM);
parent.setText("多窗口示例");
parent.setSize(300,200);
//設置父窗口圖標
Image image = new Image(display, "E:\\IMAG0016.jpg");
parent.setImage(image);
Button addShell = new Button(parent, SWT.CENTER);
addShell.setText("創建子窗口");
addShell.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event){
createChildrenShell(parent,"子窗口");
}
});
addShell.pack();
parent.open();
while(!parent.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();
}
public static Shell createChildrenShell(Shell parent,String childrenName){
//創建子窗口
Shell shell = new Shell(parent, SWT.DIALOG_TRIM);
shell.setText(childrenName);
shell.setSize(100, 100);
shell.open();
return shell;
}


發佈了42 篇原創文章 · 獲贊 9 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章