package com.sinosafe.swtdemo.welcome;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
/**
*
* @author zhong39
* 一個簡單的啟動界面的例子
*
*/
public class WelcomeInterface {
private static Shell shell;
public static void main(String[] args) {
Display display = new Display();
shell = new Shell(display, SWT.NO_TRIM |SWT.ON_TOP);
createContents(shell);
shell.setBounds(400, 200, 310, 250);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
protected static void createContents(Shell shell) {
shell.setLayout(new FillLayout());
Composite cm = new Composite(shell ,SWT.None);
cm.setLayout(new GridLayout(1,false));
Image ico = new Image(Display.getDefault(), "icons/welcome.gif");
Label label = new Label(cm,SWT.None);
label.setImage(ico);
final ProgressBar progressBar = new ProgressBar(cm, SWT.INDETERMINATE);
progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
}
具體在我一個應用程序中怎么使用,
我暫時的想法是在程序啟動界面開始時先傳一個display過去,先啟動這個界面,在啟動應用程序界面,和要加載的數據,最后調用welcomeClose方法來關閉,下面是,修改過的代碼.
package com.sinosafe.premium.application;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
/**
*
* @author zhong39
*
*/
public class WelcomeInterface {
private Shell welcomeShell;
public void open(Display display) {
//Display display = new Display();
welcomeShell = new Shell(display, SWT.NO_TRIM);
createContents(welcomeShell);
welcomeShell.setBounds(400, 200, 310, 250);
welcomeShell.open();
}
protected void createContents(Shell shell) {
shell.setLayout(new FillLayout());
Composite cm = new Composite(shell ,SWT.None);
cm.setLayout(new GridLayout(1,false));
Image welcome = new Image(Display.getDefault(), "images/welcome.gif");
Label label = new Label(cm,SWT.None);
label.setImage(welcome);
ProgressBar progressBar = new ProgressBar(cm, SWT.INDETERMINATE);
progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
public void welcomeClose(){
welcomeShell.close();
}
}
總的來說就是shell的風格沒有邊框就是,其他的沒什么特別的,還有圖片的話,這個大家一定得弄個上去,不然的話肯定是顯示不出來了。
好了,第開天辟地的第一篇就寫個浮淺的東西,主要是這方面的網上好難早,所以我寫的關于這方面的我個人的愚見,希望能節省到有這方面需要的人的時間。